Verwendung

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

Typdeklaration

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

Mitglieder 7

NameTypErforderlichBeschreibung
gtExtract<V, string | number>Nein—
gteExtract<V, string | number>Nein—
ltExtract<V, string | number>Nein—
lteExtract<V, string | number>Nein—
notVNeinRows whose column isn't this value: NULL isn't 'a', and { not: null } is every non-NULL.
inreadonly V[]NeinRows whose column is one of these; null among them matches NULL.
like[Extract<V, string>] extends [never] ? never : stringNeinSQL's LIKE: % is any run of characters, _ one; ASCII letters match either case.
Generiert aus den öffentlichen TypeScript-Deklarationen: Signaturen, Props und Standardwerte stammen aus der geprüften Quelle, Beschreibungen aus deren JSDoc. Kein Standardwert ist erfunden.