Skip to content

Conversation

gammazero
Copy link
Contributor

@gammazero gammazero commented Aug 14, 2025

Add a QueryIter function that returns a go iterator that allows ranging over query results. The range yields two values, a result Entry and an error. If an error is returned then iteration stops.

The QueryIterator function is a convenience that helps ensure query results are closed after use and that errors are checked.

Example:

qry := query.Query{
	Prefix: keyPrefix,
}
var foundVal []byte
for ent, err := range QueryIter(dstore, qry) {
	if err != nil {
		return err
	}
	if ent.Key == lookingFor {
		foundVal = ent.Val
		break
	}
}

- Check context for error on each iteration.
- Test that canceling context stops iteration.
@gammazero gammazero changed the title Feat/query iterator feat: query iterator Aug 14, 2025
@gammazero gammazero added topic/devexp Developer Experience kind/enhancement A net-new feature or improvement to an existing feature labels Aug 14, 2025
@guillaumemichel guillaumemichel self-requested a review August 19, 2025 14:49
@guillaumemichel guillaumemichel removed their request for review August 19, 2025 15:39
@gammazero gammazero merged commit 0797048 into master Aug 21, 2025
10 checks passed
@gammazero gammazero deleted the feat/query-iterator branch August 21, 2025 04:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement A net-new feature or improvement to an existing feature topic/devexp Developer Experience
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants