LiveQueryCollectionConfig

接口:LiveQueryCollectionConfig<TContext, TResult>

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

实时查询集合选项的配置接口

示例

typescript
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,
}
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,
}

类型参数

TContext extends Context

TResult 继承 object = GetResult<TContext> & object

属性

gcTime?

ts
optional gcTime: number;
optional gcTime: number;

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

集合的 GC 时间


getKey()?

ts
optional getKey: (item) => string | number;
optional getKey: (item) => string | number;

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

用于从结果项中提取键的函数。如果未提供,则默认使用 D2 流中的键。

参数

item

TResult

Returns (返回)

string | number


id?

ts
optional id: string;
optional id: string;

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

集合的唯一标识符。如果未提供,则默认为带自动递增数字的 live-query-${number}


onDelete?

ts
optional onDelete: DeleteMutationFn<TResult, string | number, Record<string, Fn>>;
optional onDelete: DeleteMutationFn<TResult, string | number, Record<string, Fn>>;

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


onInsert?

ts
optional onInsert: InsertMutationFn<TResult, string | number, Record<string, Fn>>;
optional onInsert: InsertMutationFn<TResult, string | number, Record<string, Fn>>;

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

可选的 mutation 处理程序


onUpdate?

ts
optional onUpdate: UpdateMutationFn<TResult, string | number, Record<string, Fn>>;
optional onUpdate: UpdateMutationFn<TResult, string | number, Record<string, Fn>>;

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


query

ts
query: 
  | QueryBuilder<TContext>
| (q) => QueryBuilder<TContext>;
query: 
  | QueryBuilder<TContext>
| (q) => QueryBuilder<TContext>;

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

定义实时查询的查询构建器函数


schema?

ts
optional schema: StandardSchemaV1<unknown, unknown>;
optional schema: StandardSchemaV1<unknown, unknown>;

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

用于验证的可选 schema


startSync?

ts
optional startSync: boolean;
optional startSync: boolean;

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

立即开始同步/查询

我们的合作伙伴
Code Rabbit
Electric
Prisma
订阅 Bytes

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

Bytes

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

订阅 Bytes

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

Bytes

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