Open
Conversation
Implements the queryOnce function as described in the RFC. This provides
a lightweight wrapper around createLiveQueryCollection that:
- Creates a live query collection with gcTime: 0
- Preloads the data
- Extracts results as an array (or single item for findOne)
- Automatically cleans up the collection
The queryOnce function:
- Accepts either a query function or config object
- Supports all query builder operations (where, select, join, orderBy, etc.)
- Properly handles findOne() queries returning single results
- Ensures cleanup happens even on error via try/finally
Use cases:
- AI/LLM context building
- Data export
- Background processing
- Testing
API:
```typescript
// Simple query
const users = await queryOnce((q) =>
q.from({ user: usersCollection })
.where(({ user }) => eq(user.active, true))
)
// Single result with findOne
const user = await queryOnce((q) =>
q.from({ user: usersCollection })
.where(({ user }) => eq(user.id, 1))
.findOne()
)
// Config object form
const orders = await queryOnce({
query: (q) => q.from({ order: ordersCollection }).limit(100)
})
```
|
Cursor Agent can help with this pull request. Just |
🦋 Changeset detectedLatest commit: c2ed7ad The changes in this PR will be included in the next version bump. This PR includes changesets to release 14 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
More templates
@tanstack/angular-db
@tanstack/db
@tanstack/db-ivm
@tanstack/electric-db-collection
@tanstack/offline-transactions
@tanstack/powersync-db-collection
@tanstack/query-db-collection
@tanstack/react-db
@tanstack/rxdb-db-collection
@tanstack/solid-db
@tanstack/svelte-db
@tanstack/trailbase-db-collection
@tanstack/vue-db
commit: |
Contributor
|
Size Change: +385 B (+0.42%) Total Size: 92.4 kB
ℹ️ View Unchanged
|
Contributor
|
Size Change: 0 B Total Size: 3.7 kB ℹ️ View Unchanged
|
Co-authored-by: sam.willis <sam.willis@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🎯 Changes
Implements the
queryOnceAPI, enabling one-shot execution of queries. This function creates a temporary live query collection, preloads data, extracts results, and automatically cleans up the collection.This is useful for scenarios where a persistent live query is not needed, such as:
It provides two overloads: a simple query function and a config object, supporting all standard query builder features including filtering, projection, joins, ordering, pagination, and
findOne().✅ Checklist
pnpm test:pr.🚀 Release Impact