UNPKG

agnostic-query

Version:

Type-safe fluent builder for portable query schemas. Runtime-agnostic, database-agnostic — the same QuerySchema drives Drizzle, Kysely, db0, or raw SQL.

17 lines (16 loc) 745 B
import { _toSql, buildWhere, quoteIdent, toSqlOrderBy as toSqlOrderBy$1 } from "./common.js"; //#region src/sql/sqlite.ts const fieldToStr = (field) => { if (field.length === 1) return quoteIdent(field[0]); const [root, ...rest] = field; const path = rest.map((p) => typeof p === "number" ? `[${p}]` : `.${p.replace(/'/g, "''")}`).join(""); return `json_extract(${quoteIdent(root)}, '$${path}')`; }; const toSqlWhere = (where) => { if (!where) return; return buildWhere(where, fieldToStr, () => "?"); }; const toSqlOrderBy = (orderBy) => toSqlOrderBy$1(orderBy, fieldToStr); const toSql = (json) => _toSql(json, fieldToStr, (w) => buildWhere(w, fieldToStr, () => "?")); //#endregion export { fieldToStr, toSql, toSqlOrderBy, toSqlWhere };