- 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
LiveQueryCollectionConfig
Defined in: packages/db/src/query/live/types.ts:65
Configuration interface for live query collection options
Example#
const config: LiveQueryCollectionConfig<any, any> = {
// id is optional - will auto-generate "live-query-1", "live-query-2", etc.
query: (q) => q
.from({ comment: commentsCollection })
.join(
{ user: usersCollection },
({ comment, user }) => eq(comment.user_id, user.id)
)
.where(({ comment }) => eq(comment.active, true))
.select(({ comment, user }) => ({
id: comment.id,
content: comment.content,
authorName: user.name,
})),
// getKey is optional - defaults to using stream key
getKey: (item) => item.id,
}Type Parameters#
TContext#
TContext extends Context
TResult#
TResult extends object = RootQueryResult<TContext>
Properties#
defaultStringCollation?#
optional defaultStringCollation: StringCollationConfig;Defined in: packages/db/src/query/live/types.ts:121
Optional compare options for string sorting. If provided, these will be used instead of inheriting from the FROM collection.
gcTime?#
optional gcTime: number;Defined in: packages/db/src/query/live/types.ts:110
GC time for the collection
getKey()?#
optional getKey: (item) => string | number;Defined in: packages/db/src/query/live/types.ts:88
Function to extract the key from result items If not provided, defaults to using the key from the D2 stream
Parameters#
item#
TResult
Returns#
string | number
id?#
optional id: string;Defined in: packages/db/src/query/live/types.ts:73
Unique identifier for the collection If not provided, defaults to live-query-${number} with auto-incrementing number
onDelete?#
optional onDelete:
| DeleteMutationFn<TResult, string | number, UtilsRecord, void>
| DeleteMutationFn<TResult, string | number, UtilsRecord, any>;Defined in: packages/db/src/query/live/types.ts:100
onInsert?#
optional onInsert:
| InsertMutationFn<TResult, string | number, UtilsRecord, void>
| InsertMutationFn<TResult, string | number, UtilsRecord, any>;Defined in: packages/db/src/query/live/types.ts:98
Optional mutation handlers
onUpdate?#
optional onUpdate:
| UpdateMutationFn<TResult, string | number, UtilsRecord, void>
| UpdateMutationFn<TResult, string | number, UtilsRecord, any>;Defined in: packages/db/src/query/live/types.ts:99
query#
query:
| (q) => QueryBuilder<TContext> & RootObjectResultConstraint<TContext>
| QueryBuilder<TContext> & RootObjectResultConstraint<TContext>;Defined in: packages/db/src/query/live/types.ts:78
Query builder function that defines the live query
schema?#
optional schema: undefined;Defined in: packages/db/src/query/live/types.ts:93
Optional schema for validation
singleResult?#
optional singleResult: true;Defined in: packages/db/src/query/live/types.ts:115
If enabled the collection will return a single object instead of an array
startSync?#
optional startSync: boolean;Defined in: packages/db/src/query/live/types.ts:105
Start sync / the query immediately