Skip to content

Filters playground

This page runs the real @xtandard/lib/filters code in your browser. It uses an example products resource with one field of each kind. Edit the JSON and switch tabs to see:

-- parameterized
WHERE ("products"."name" ILIKE ? AND ("products"."price" >= ? AND "products"."price" <= ?) AND "products"."status" IN (?, ?))
-- bindings: [ "%lamp%", 10, 100, "active", "draft" ]

-- inlined for reading
WHERE ("products"."name" ILIKE '%lamp%' AND ("products"."price" >= 10 AND "products"."price" <= 100) AND "products"."status" IN ('active', 'draft'))

The spec behind this page, as you would write it for the Knex adapter:

import {
arrayField,
booleanField,
buildWhereSql,
dateField,
enumField,
numberField,
textField,
} from "@xtandard/lib/filters/knex";
const spec = {
name: textField({ column: "products.name" }),
status: enumField({ column: "products.status" }),
price: numberField({ column: "products.price" }),
inStock: booleanField({ column: "products.in_stock" }),
tags: arrayField({ column: "products.tags" }),
createdAt: dateField({ column: "products.created_at" }),
};
const fragment = buildWhereSql({ spec, filters, resolveDate, dialect: "postgres" }); // { sql, bindings } | null