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 |
|
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: |
|
Size Change: +359 B (+0.39%) Total Size: 92.3 kB
ℹ️ View Unchanged
|
|
Size Change: 0 B Total Size: 3.7 kB ℹ️ View Unchanged
|
🎯 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