Reference
Filter builder
Build typed filter trees in scope functions, custom steps and tests.
createQueryFilterBuilder() builds filter trees in server code: scope functions, custom steps and tests. Every method is typed against the field paths you give it.
Import and create
import { createQueryFilterBuilder } from "drizzle-resource";
const f = createQueryFilterBuilder<"status" | "customer.name" | "createdAt">();
The type parameter is the union of valid field paths. Inside query.scope the builder is already typed from the resource, so you don't pass it yourself.
Conditions
Each returns a QueryFilterCondition. between takes { from, to }, as in a request; leave out one end for an open range.
f.is("status", "active");
f.isNot("status", "cancelled");
f.isAnyOf("status", ["pending", "processing"]);
f.contains("customer.name", "acme");
f.gt("totalAmount", 100);
f.gte("totalAmount", 100);
f.lt("totalAmount", 1000);
f.lte("totalAmount", 1000);
f.between("createdAt", { from: "2026-01-01", to: "2026-12-31" });
f.before("createdAt", "2026-06-01"); // alias for lt
f.after("createdAt", "2026-01-01"); // alias for gt
f.isEmpty("deletedAt"); // null, '' on text, [] on arrays, or no related row
f.isNotEmpty("tags.name");
Groups
// every child must match
f.and([f.is("status", "active"), f.gte("totalAmount", 100)]);
// at least one child must match
f.or([f.contains("customer.name", "acme"), f.contains("customer.name", "globex")]);
Groups nest to any depth, within the resource's maxFilterDepth:
f.and([
f.isNot("status", "cancelled"),
f.or([
f.gte("totalAmount", 1000),
f.and([f.contains("customer.name", "acme"), f.after("createdAt", "2026-01-01")]),
]),
]);
In a scope
scope: (f: ExampleFilterBuilder, ctx: { orgId: string }) =>
f.and([f.is("customer.orgId", ctx.orgId), f.is("deletedAt", null)]),
};
f is already typed from the resource.
In a custom step
const strategyConfig = {
strategy: {
ids: async ({ request, utils }: any) => {
const extraFilter = f.and([f.is("status", "active")]);
const where = utils.buildWhereClause({
filters: [...request.filters, extraFilter],
search: request.search,
});
return where;
},
},
};
Return types
import type {
QueryFilterCondition,
QueryFilterGroup,
QueryFilterNode,
QueryFilterOperator,
QueryFilters,
} from "drizzle-resource";
type QueryFilterConditionExample<TField extends string> = QueryFilterCondition<TField>;
type QueryFilterGroupExample<TField extends string> = QueryFilterGroup<TField>;
type QueryFilterNodeExample<TField extends string> = QueryFilterNode<TField>;
type QueryFiltersExample<TField extends string> = QueryFilters<TField>;
type QueryFilterOperatorExample = QueryFilterOperator;