combineWhere
function combineWhere(...conditions): SQL<unknown> | undefined;Defined in: filters/drizzle/pagination.ts:45
AND together the defined conditions, skipping undefined ones: typically the filter
WHERE from buildWhere and the keyset seek from createDrizzleKeyset().where(...), which
is undefined on the first page. Returns undefined when every input is undefined.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
…conditions |
(SQL<unknown> | undefined)[] |
Returns
Section titled “Returns”SQL<unknown> | undefined
Example
Section titled “Example”import { integer, PgDialect, pgTable, text } from "drizzle-orm/pg-core";import { buildWhere, combineWhere, createDrizzleKeyset, numberField } from "@xtandard/lib/filters/drizzle";
const posts = pgTable("posts", { id: text("id").primaryKey(), views: integer("views") });const { where: filterWhere } = buildWhere({ spec: { views: numberField({ column: posts.views }) }, filters: [{ field: "views", filter: { kind: "number", operator: "gte", value: 100 } }],});const keyset = createDrizzleKeyset({ sort: [{ key: "id", order: "asc" }], columns: { id: posts.id } });const where = combineWhere(filterWhere, keyset.where({ id: "p_9" }));const { sql, params } = new PgDialect().sqlToQuery(where!);// sql → '("posts"."views" >= $1 and "posts"."id" > $2)', params → [100, "p_9"]combineWhere(undefined, undefined); // → undefined