Utilisation

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' } });
}

Déclaration du type

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

Membres 5

NomTypeRequisDescription
namelecture seulestringOui—
schemalecture seuleSchema<T>Oui—
insert(rows: T | readonly T[]) => Promise<void>OuiInserts every row in one transaction: all of them land, or none.
update(where: Where<T>, changes: Partial<T>) => Promise<void>Oui—
delete(where: Where<T>) => Promise<void>OuiDeletes the rows where matches: {} matches every row.
insert — signatures de méthode

Signatures

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

Paramètres

NomTypeRequisDescription
rowsT | readonly T[]Oui—

Retourne

Promise<void>

update — signatures de méthode

Signatures

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

Paramètres

NomTypeRequisDescription
whereWhere<T>Oui—
changesPartial<T>Oui—

Retourne

Promise<void>

delete — signatures de méthode

Signatures

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

Paramètres

NomTypeRequisDescription
whereWhere<T>Oui—

Retourne

Promise<void>

Généré depuis les déclarations TypeScript publiques : signatures, props et valeurs par défaut viennent de la source vérifiée, les descriptions de sa JSDoc. Aucune valeur par défaut n'est inventée.