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 Comparison<V> {
  gt?: Extract<V, string | number>;
  gte?: Extract<V, string | number>;
  lt?: Extract<V, string | number>;
  lte?: Extract<V, string | number>;
  /** Rows whose column isn't this value: NULL isn't `'a'`, and `{ not: null }` is every non-NULL. */
  not?: V;
  /** Rows whose column is one of these; `null` among them matches NULL. */
  in?: readonly V[];
  /** SQL's LIKE: `%` is any run of characters, `_` one; ASCII letters match either case. */
  like?: [Extract<V, string>] extends [never] ? never : string;
}

Membros 7

NomeTipoObrigatórioDescrição
gtExtract<V, string | number>Não—
gteExtract<V, string | number>Não—
ltExtract<V, string | number>Não—
lteExtract<V, string | number>Não—
notVNãoRows whose column isn't this value: NULL isn't 'a', and { not: null } is every non-NULL.
inreadonly V[]NãoRows whose column is one of these; null among them matches NULL.
like[Extract<V, string>] extends [never] ? never : stringNãoSQL's LIKE: % is any run of characters, _ one; ASCII letters match either case.
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.