toFilterWhereSql
function toFilterWhereSql(input): Fragment | null;Defined in: filters/knex.ts:282
Render an already-compiled CompiledWhere AST (from compileFilters /
compileFilterNode in @xtandard/lib/filters) to a parameterized { sql, bindings }
fragment, looking each field up in columns (column strings, validated and quoted).
Conditions on fields missing from columns are dropped; null (or an AST that drops to
nothing) gives null. Most code calls buildWhereSql, which compiles and renders in one step.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
input |
{ columns: Record<string, string>; dialect?: SqlDialect; where: | CompiledWhere | null; } |
input.columns |
Record<string, string> |
input.dialect? |
SqlDialect |
input.where |
| CompiledWhere | null |
Returns
Section titled “Returns”Fragment | null
Example
Section titled “Example”import { toFilterWhereSql } from "@xtandard/lib/filters/knex";
toFilterWhereSql({ where: { type: "and", nodes: [ { type: "cond", cond: { field: "amount", op: "gt", value: 5 } }, { type: "cond", cond: { field: "name", op: "isNotNull" } }, ] }, columns: { amount: "amount", name: "name" },});// → { sql: '("amount" > ? AND "name" IS NOT NULL)', bindings: [5] }