arrayField
const arrayField: (input) => KyselyFieldSpec;Defined in: filters/kysely.ts:147
Allow-list a public field as an array filter over a column given as a Kysely reference
string ("posts.tags") or a raw expression. The SQL depends on dialect: a native array
with @>/<@/&& on Postgres, a JSON column with json_contains/json_overlaps on MySQL,
and json_each(…) subqueries on SQLite.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
input |
{ column: KyselyTarget; } |
input.column |
KyselyTarget |
Returns
Section titled “Returns”Example
Section titled “Example”import type { ColumnFilter } from "@xtandard/lib/filters";import { arrayField, buildWhere } from "@xtandard/lib/filters/kysely";
const spec = { tags: arrayField({ column: "posts.tags" }) };const filters: ColumnFilter[] = [ { field: "tags", filter: { kind: "array", operator: "arrayOverlaps", values: ["ts", "js"] } },];buildWhere({ spec, filters }).where!.compile(db).sql; // → '"posts"."tags" && $1'buildWhere({ spec, filters, dialect: "mysql" }).where!.compile(db).sql;// → 'json_overlaps("posts"."tags", $1)' with a Postgres `db`;// a MySQL Kysely instance prints 'json_overlaps(`posts`.`tags`, ?)'