Utilização

Reuse a filter when querying a typed table.

tsx
// Reuse a filter when querying a typed table.
import { db, type Comparison, type Table } from 'kuito';

type Product = { id: string; price: number };
export function affordableProducts(products: Table<Product>) {
  const price: Comparison<number> = { gte: 0, lte: 50 };
  return db.query(products, { where: { price }, orderBy: { price: 'asc' } });
}

Declaração do tipo

ts
export interface Table<T> {
  readonly name: string;
  readonly schema: Schema<T>;
  /** Inserts every row in one transaction: all of them land, or none. */
  insert(rows: T | readonly T[]): Promise<void>;
  update(where: Where<T>, changes: Partial<T>): Promise<void>;
  /** Deletes the rows `where` matches: `{}` matches every row. */
  delete(where: Where<T>): Promise<void>;
}

Membros 5

NomeTipoObrigatórioDescrição
namesó de leiturastringSim—
schemasó de leituraSchema<T>Sim—
insert(rows: T | readonly T[]) => Promise<void>SimInserts every row in one transaction: all of them land, or none.
update(where: Where<T>, changes: Partial<T>) => Promise<void>Sim—
delete(where: Where<T>) => Promise<void>SimDeletes the rows where matches: {} matches every row.
insert — assinaturas de método

Assinaturas

ts
(rows: T | readonly T[]): Promise<void>

Parâmetros

NomeTipoObrigatórioDescrição
rowsT | readonly T[]Sim—

Devolve

Promise<void>

update — assinaturas de método

Assinaturas

ts
(where: Where<T>, changes: Partial<T>): Promise<void>

Parâmetros

NomeTipoObrigatórioDescrição
whereWhere<T>Sim—
changesPartial<T>Sim—

Devolve

Promise<void>

delete — assinaturas de método

Assinaturas

ts
(where: Where<T>): Promise<void>

Parâmetros

NomeTipoObrigatórioDescrição
whereWhere<T>Sim—

Devolve

Promise<void>

Gerado a partir das declarações TypeScript públicas: assinaturas, props e predefinições vêm da fonte verificada, as descrições da sua JSDoc. Nenhuma predefinição é inventada.