buildWhere
function buildWhere(input): object;Defined in: filters/kysely.ts:337
Compile a flat, AND-combined list of column filters into a Kysely boolean expression for
.where(where). Only fields in spec whose kind matches the filter’s kind are kept; the
rest are silently dropped. where is undefined when nothing survives (skip the .where
call then). A date preset filter needs resolveDate (it throws without one). dialect
(default "postgres") changes the array ops, ilike and the LIKE escape clause.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
input |
{ dialect?: SqlDialect; filters: ColumnFilter[]; resolveDate?: DateFilterResolver; spec: KyselyFilterSpec; } |
input.dialect? |
SqlDialect |
input.filters |
ColumnFilter[] |
input.resolveDate? |
DateFilterResolver |
input.spec |
KyselyFilterSpec |
Returns
Section titled “Returns”object
| Name | Type | Defined in |
|---|---|---|
where |
RawBuilder<SqlBool> | undefined |
filters/kysely.ts:342 |
Example
Section titled “Example”import { buildWhere, numberField, textField } from "@xtandard/lib/filters/kysely";
const spec = { name: textField({ column: "tasks.name" }), amount: numberField({ column: "tasks.amount" }) };const { where } = buildWhere({ spec, filters: [ { field: "name", filter: { kind: "text", operator: "startsWith", value: "Re" } }, { field: "amount", filter: { kind: "number", operator: "gte", value: 100 } },] });let query = db.selectFrom("tasks").selectAll(); // db: your Kysely instanceif (where) query = query.where(where);const { sql, parameters } = query.compile();// sql → 'select * from "tasks" where ("tasks"."name" ilike $1 and "tasks"."amount" >= $2)'// parameters → ["Re%", 100]