Skip to content

toFilterPredicate

function toFilterPredicate<Row>(input): FilterPredicate<Row>;

Defined in: filters/memory.ts:487

Render an already-compiled CompiledWhere AST (from compileFilters / compileFilterNode in @xtandard/lib/filters) to a row predicate, looking each field up in paths (public field name → MemoryAccessor). Conditions on fields missing from paths are dropped; null (or an AST that drops to nothing) gives a predicate that matches every row. Evaluation uses SQL’s three-valued logic: a comparison with NULL is UNKNOWN, not keeps UNKNOWN, and a row matches only when the whole tree is TRUE. Most code calls buildFilterPredicate, which compiles and renders in one step.

Type Parameter Default type
Row any
Parameter Type
input { dialect?: MemoryDialect; paths: Record<string, MemoryAccessor<Row>>; where: | CompiledWhere | null; }
input.dialect? MemoryDialect
input.paths Record<string, MemoryAccessor<Row>>
input.where | CompiledWhere | null

FilterPredicate<Row>

import { toFilterPredicate } from "@xtandard/lib/filters/memory";
const predicate = toFilterPredicate({
where: { type: "not", node: { type: "cond", cond: { field: "amount", op: "gt", value: 5 } } },
paths: { amount: "amount" },
});
predicate({ amount: 3 }); // → true
predicate({ amount: 9 }); // → false
predicate({ amount: null }); // → false (NOT UNKNOWN is UNKNOWN)