liveQueryCollectionOptions

函数: liveQueryCollectionOptions()

ts
function liveQueryCollectionOptions<TContext, TResult>(config): CollectionConfig<TResult>
function liveQueryCollectionOptions<TContext, TResult>(config): CollectionConfig<TResult>

定义于: packages/db/src/query/live-query-collection.ts:117

为 createCollection 使用创建 live query collection 选项

类型参数

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] }

参数

config

LiveQueryCollectionConfig<TContext, TResult>

live query collection 的配置选项

Returns (返回)

CollectionConfig<TResult>

可以传递给 createCollection 的 collection 选项

示例

typescript
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)
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)
我们的合作伙伴
Code Rabbit
Electric
Prisma
订阅 Bytes

您的每周 JavaScript 资讯。每周一免费发送给超过 10 万开发者。

Bytes

无垃圾邮件。您可以随时取消订阅。

订阅 Bytes

您的每周 JavaScript 资讯。每周一免费发送给超过 10 万开发者。

Bytes

无垃圾邮件。您可以随时取消订阅。