File: createLiveQueryCollection.md | Updated: 11/15/2025
Search...
+ K
Auto
Docs Examples GitHub Contributors
Docs Examples GitHub Contributors
Docs Examples GitHub Contributors
Docs Examples Github Contributors
Docs Examples Github Contributors
Docs Examples Github Contributors
Docs Examples Github Contributors
Docs Examples Github Contributors
Maintainers Partners Support Learn StatsBETA Discord Merch Blog GitHub Ethos Brand Guide
Documentation
Framework
React
Version
Latest
Search...
+ K
Menu
Getting Started
Guides
Collections
Frameworks
Community
API Reference
Framework
React
Version
Latest
Menu
Getting Started
Guides
Collections
Frameworks
Community
API Reference
On this page
Copy Markdown
Function: createLiveQueryCollection()
=====================================
Call Signature
--------------
ts
function createLiveQueryCollection<TContext, TResult>(query): CollectionForContext<TContext, TResult, {
}> & object;
function createLiveQueryCollection<TContext, TResult>(query): CollectionForContext<TContext, TResult, {
}> & object;
Defined in: packages/db/src/query/live-query-collection.ts:115
Creates a live query collection directly
### Type Parameters #### TContext
TContext extends Context
TResult extends object = { [K in string | number | symbol]: (TContext["result"] extends object ? any[any] : TContext["hasJoins"] extends true ? TContext["schema"] : TContext["schema"][TContext["fromSourceName"]])[K] }
(q) => QueryBuilder <TContext>
CollectionForContext<TContext, TResult, { }> & object
typescript
// Minimal usage - just pass a query function
const activeUsers = createLiveQueryCollection(
(q) => q
.from({ user: usersCollection })
.where(({ user }) => eq(user.active, true))
.select(({ user }) => ({ id: user.id, name: user.name }))
)
// Full configuration with custom options
const searchResults = createLiveQueryCollection({
id: "search-results", // Custom ID (auto-generated if omitted)
query: (q) => q
.from({ post: postsCollection })
.where(({ post }) => like(post.title, `%${searchTerm}%`))
.select(({ post }) => ({
id: post.id,
title: post.title,
excerpt: post.excerpt,
})),
getKey: (item) => item.id, // Custom key function (uses stream key if omitted)
utils: {
updateSearchTerm: (newTerm: string) => {
// Custom utility functions
}
}
})
// Minimal usage - just pass a query function
const activeUsers = createLiveQueryCollection(
(q) => q
.from({ user: usersCollection })
.where(({ user }) => eq(user.active, true))
.select(({ user }) => ({ id: user.id, name: user.name }))
)
// Full configuration with custom options
const searchResults = createLiveQueryCollection({
id: "search-results", // Custom ID (auto-generated if omitted)
query: (q) => q
.from({ post: postsCollection })
.where(({ post }) => like(post.title, `%${searchTerm}%`))
.select(({ post }) => ({
id: post.id,
title: post.title,
excerpt: post.excerpt,
})),
getKey: (item) => item.id, // Custom key function (uses stream key if omitted)
utils: {
updateSearchTerm: (newTerm: string) => {
// Custom utility functions
}
}
})
ts
function createLiveQueryCollection<TContext, TResult, TUtils>(config): CollectionForContext<TContext, TResult, {
}> & object;
function createLiveQueryCollection<TContext, TResult, TUtils>(config): CollectionForContext<TContext, TResult, {
}> & object;
Defined in: packages/db/src/query/live-query-collection.ts:125
Creates a live query collection directly
### Type Parameters #### TContext
TContext extends Context
TResult extends object = { [K in string | number | symbol]: (TContext["result"] extends object ? any[any] : TContext["hasJoins"] extends true ? TContext["schema"] : TContext["schema"][TContext["fromSourceName"]])[K] }
TUtils extends UtilsRecord = { }
LiveQueryCollectionConfig <TContext, TResult> & object
CollectionForContext<TContext, TResult, { }> & object
typescript
// Minimal usage - just pass a query function
const activeUsers = createLiveQueryCollection(
(q) => q
.from({ user: usersCollection })
.where(({ user }) => eq(user.active, true))
.select(({ user }) => ({ id: user.id, name: user.name }))
)
// Full configuration with custom options
const searchResults = createLiveQueryCollection({
id: "search-results", // Custom ID (auto-generated if omitted)
query: (q) => q
.from({ post: postsCollection })
.where(({ post }) => like(post.title, `%${searchTerm}%`))
.select(({ post }) => ({
id: post.id,
title: post.title,
excerpt: post.excerpt,
})),
getKey: (item) => item.id, // Custom key function (uses stream key if omitted)
utils: {
updateSearchTerm: (newTerm: string) => {
// Custom utility functions
}
}
})
// Minimal usage - just pass a query function
const activeUsers = createLiveQueryCollection(
(q) => q
.from({ user: usersCollection })
.where(({ user }) => eq(user.active, true))
.select(({ user }) => ({ id: user.id, name: user.name }))
)
// Full configuration with custom options
const searchResults = createLiveQueryCollection({
id: "search-results", // Custom ID (auto-generated if omitted)
query: (q) => q
.from({ post: postsCollection })
.where(({ post }) => like(post.title, `%${searchTerm}%`))
.select(({ post }) => ({
id: post.id,
title: post.title,
excerpt: post.excerpt,
})),
getKey: (item) => item.id, // Custom key function (uses stream key if omitted)
utils: {
updateSearchTerm: (newTerm: string) => {
// Custom utility functions
}
}
})
