DB Docs
API Reference
- Core API Reference
- Collection
- createCollection
- liveQueryCollectionOptions
- createLiveQueryCollection
- createOptimisticAction
- createTransaction
- Electric DB Collection
- electricCollectionOptions
- Query DB Collection
- queryCollectionOptions
- RxDB DB Collection
- rxdbCollectionOptions
- PowerSync Collection
- powerSyncCollectionOptions
- createIndexedDB
- indexedDBCollectionOptions
- React Hooks
- useLiveQuery
AI/LLM: This documentation page is available in plain markdown format at/db/latest/docs/reference/functions/liveQueryCollectionOptions.md
API Reference
liveQueryCollectionOptions
ts
function liveQueryCollectionOptions<TQuery, TContext, TResult>(config): CollectionConfigForContext<TContext, TResult, {
}> & object;Defined in: packages/db/src/query/live-query-collection.ts:72
Creates live query collection options for use with createCollection
Type Parameters#
TQuery#
TQuery extends QueryBuilder<any>
TContext#
TContext extends Context = ExtractContext<TQuery>
TResult#
TResult extends object = RootQueryResult<TContext>
Parameters#
config#
LiveQueryCollectionConfig<TContext, TResult> & object
Configuration options for the live query collection
Returns#
CollectionConfigForContext<TContext, TResult, { }> & object
Collection options that can be passed to createCollection
Example#
ts
const options = liveQueryCollectionOptions({
// id is optional - will auto-generate if not provided
query: (q) => q
.from({ post: postsCollection })
.where(({ post }) => eq(post.published, true))
.select(({ post }) => ({
id: post.id,
title: post.title,
content: post.content,
})),
// getKey is optional - will use stream key if not provided
})
const collection = createCollection(options)