toDrizzleWhere
function toDrizzleWhere(input): SQL<unknown> | undefined;Defined in: filters/drizzle/where.ts:116
Render an already-compiled CompiledWhere AST (from compileFilters /
compileFilterNode in @xtandard/lib/filters) to a Drizzle SQL, 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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
input |
{ columns: Record<string, AnyColumn>; where: | CompiledWhere | null; } |
input.columns |
Record<string, AnyColumn> |
input.where |
| CompiledWhere | null |
Returns
Section titled “Returns”SQL<unknown> | undefined
Example
Section titled “Example”import { integer, PgDialect, pgTable, text } from "drizzle-orm/pg-core";import { toDrizzleWhere } from "@xtandard/lib/filters/drizzle";
const tasks = pgTable("tasks", { name: text("name"), amount: integer("amount") });const where = toDrizzleWhere({ 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, params } = new PgDialect().sqlToQuery(where!);// sql → '("tasks"."amount" > $1 and "tasks"."name" is not null)', params → [5]