Skip to content

toDrizzleRqbV1Callback

function toDrizzleRqbV1Callback(input): RqbV1WhereCallback;

Defined in: filters/drizzle-rqb.ts:453

Render an already-compiled CompiledWhere AST to an RQB v1 where callback (fields, operators) => SQL | undefined. columns maps each field to a schema property key, which the callback looks up in the fields drizzle passes in. Conditions on unknown fields are dropped; when nothing is left the callback returns undefined. Most code calls buildRqbV1Where, which compiles and renders in one step.

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

RqbV1WhereCallback

import { getOperators } from "drizzle-orm";
import { integer, PgDialect, pgTable, text } from "drizzle-orm/pg-core";
import { toDrizzleRqbV1Callback } from "@xtandard/lib/filters/drizzle-rqb";
const tasks = pgTable("tasks", { name: text("name"), amount: integer("amount") });
const where = toDrizzleRqbV1Callback({
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" },
});
// drizzle calls where(fields, getOperators()) itself; calling it by hand shows the SQL.
new PgDialect().sqlToQuery(where({ ...tasks }, getOperators())!).sql;
// → '("tasks"."amount" > $1 and "tasks"."name" is not null)'