Skip to content

toKyselyWhere

function toKyselyWhere(input): RawBuilder<SqlBool> | undefined;

Defined in: filters/kysely.ts:276

Render an already-compiled CompiledWhere AST (from compileFilters / compileFilterNode in @xtandard/lib/filters) to a Kysely boolean expression, looking each field up in columns. Conditions on fields missing from columns are dropped; null (or an AST that drops to nothing) gives undefined. Most code calls buildWhere, which compiles and renders in one step.

Parameter Type
input { columns: Record<string, KyselyTarget>; dialect?: SqlDialect; where: | CompiledWhere | null; }
input.columns Record<string, KyselyTarget>
input.dialect? SqlDialect
input.where | CompiledWhere | null

RawBuilder<SqlBool> | undefined

import { toKyselyWhere } from "@xtandard/lib/filters/kysely";
const where = toKyselyWhere({
where: { type: "and", nodes: [
{ type: "cond", cond: { field: "amount", op: "gt", value: 5 } },
{ type: "cond", cond: { field: "name", op: "isNotNull" } },
] },
columns: { amount: "tasks.amount", name: "tasks.name" },
});
const { sql, parameters } = where!.compile(db); // db: your Kysely instance
// sql → '("tasks"."amount" > $1 and "tasks"."name" is not null)', parameters → [5]