@saltcorn/db-common
Advanced tools
Comparing version 0.9.6-beta.12 to 0.9.6-beta.13
@@ -199,2 +199,7 @@ "use strict"; | ||
.join(" or ")); | ||
const whereAnd = (phs) => (ors) => wrapParens(ors | ||
.map((vi) => Object.entries(vi) | ||
.map((kv) => whereClause(phs)(kv)) | ||
.join(" and ")) | ||
.join(" and ")); | ||
const equals = ([v1, v2], phs) => { | ||
@@ -230,37 +235,39 @@ const pVal = (v) => typeof v === "symbol" | ||
? whereOr(phs)(v) | ||
: typeof (v || {}).slugify !== "undefined" | ||
? slugifyQuery(k, v.slugify, phs) | ||
: k === "not" && typeof v === "object" | ||
? `not (${Object.entries(v) | ||
.map((kv) => whereClause(phs)(kv)) | ||
.join(" and ")})` | ||
: k === "eq" && Array.isArray(v) | ||
? // @ts-ignore | ||
equals(v, phs) | ||
: v && v.or && Array.isArray(v.or) | ||
? wrapParens(v.or.map((vi) => whereClause(phs)([k, vi])).join(" or ")) | ||
: Array.isArray(v) | ||
? v.map((vi) => whereClause(phs)([k, vi])).join(" and ") | ||
: typeof (v || {}).ilike !== "undefined" | ||
? `${quote((0, exports.sqlsanitizeAllowDots)(k))} ${phs.is_sqlite ? "LIKE" : "ILIKE"} '%' || ${phs.push(v.ilike)} || '%'` | ||
: v instanceof RegExp | ||
? `${quote((0, exports.sqlsanitizeAllowDots)(k))} ${phs.is_sqlite ? "REGEXP" : "~"} ${phs.push(v.source)}` | ||
: typeof (v || {}).gt !== "undefined" && | ||
typeof (v || {}).lt !== "undefined" | ||
? `${castDate(v.day_only, phs.is_sqlite, quote((0, exports.sqlsanitizeAllowDots)(k)))}>${v.equal ? "=" : ""}${castDate(v.day_only, phs.is_sqlite, phs.push(v.gt))} and ${castDate(v.day_only, phs.is_sqlite, quote((0, exports.sqlsanitizeAllowDots)(k)))}<${v.equal ? "=" : ""}${castDate(v.day_only, phs.is_sqlite, phs.push(v.lt))}` | ||
: typeof (v || {}).gt !== "undefined" | ||
? `${castDate(v.day_only, phs.is_sqlite, quote((0, exports.sqlsanitizeAllowDots)(k)))}>${v.equal ? "=" : ""}${castDate(v.day_only, phs.is_sqlite, phs.push(v.gt))}` | ||
: typeof (v || {}).lt !== "undefined" | ||
? `${castDate(v.day_only, phs.is_sqlite, quote((0, exports.sqlsanitizeAllowDots)(k)))}<${v.equal ? "=" : ""}${castDate(v.day_only, phs.is_sqlite, phs.push(v.lt))}` | ||
: typeof (v || {}).inSelect !== "undefined" | ||
? (0, exports.subSelectWhere)(phs)(k, v) | ||
: typeof (v || {}).inSelectWithLevels !== "undefined" | ||
? inSelectWithLevels(phs)(k, v) | ||
: typeof (v || {}).json !== "undefined" | ||
? jsonWhere(k, v.json, phs) | ||
: v === null | ||
? `${quote((0, exports.sqlsanitizeAllowDots)(k))} is null` | ||
: k === "not" | ||
? `not (${typeof v === "symbol" ? v.description : phs.push(v)})` | ||
: `${quote((0, exports.sqlsanitizeAllowDots)(k))}=${typeof v === "symbol" ? v.description : phs.push(v)}`; | ||
: k === "and" && Array.isArray(v) | ||
? whereAnd(phs)(v) | ||
: typeof (v || {}).slugify !== "undefined" | ||
? slugifyQuery(k, v.slugify, phs) | ||
: k === "not" && typeof v === "object" | ||
? `not (${Object.entries(v) | ||
.map((kv) => whereClause(phs)(kv)) | ||
.join(" and ")})` | ||
: k === "eq" && Array.isArray(v) | ||
? // @ts-ignore | ||
equals(v, phs) | ||
: v && v.or && Array.isArray(v.or) | ||
? wrapParens(v.or.map((vi) => whereClause(phs)([k, vi])).join(" or ")) | ||
: Array.isArray(v) | ||
? v.map((vi) => whereClause(phs)([k, vi])).join(" and ") | ||
: typeof (v || {}).ilike !== "undefined" | ||
? `${quote((0, exports.sqlsanitizeAllowDots)(k))} ${phs.is_sqlite ? "LIKE" : "ILIKE"} '%' || ${phs.push(v.ilike)} || '%'` | ||
: v instanceof RegExp | ||
? `${quote((0, exports.sqlsanitizeAllowDots)(k))} ${phs.is_sqlite ? "REGEXP" : "~"} ${phs.push(v.source)}` | ||
: typeof (v || {}).gt !== "undefined" && | ||
typeof (v || {}).lt !== "undefined" | ||
? `${castDate(v.day_only, phs.is_sqlite, quote((0, exports.sqlsanitizeAllowDots)(k)))}>${v.equal ? "=" : ""}${castDate(v.day_only, phs.is_sqlite, phs.push(v.gt))} and ${castDate(v.day_only, phs.is_sqlite, quote((0, exports.sqlsanitizeAllowDots)(k)))}<${v.equal ? "=" : ""}${castDate(v.day_only, phs.is_sqlite, phs.push(v.lt))}` | ||
: typeof (v || {}).gt !== "undefined" | ||
? `${castDate(v.day_only, phs.is_sqlite, quote((0, exports.sqlsanitizeAllowDots)(k)))}>${v.equal ? "=" : ""}${castDate(v.day_only, phs.is_sqlite, phs.push(v.gt))}` | ||
: typeof (v || {}).lt !== "undefined" | ||
? `${castDate(v.day_only, phs.is_sqlite, quote((0, exports.sqlsanitizeAllowDots)(k)))}<${v.equal ? "=" : ""}${castDate(v.day_only, phs.is_sqlite, phs.push(v.lt))}` | ||
: typeof (v || {}).inSelect !== "undefined" | ||
? (0, exports.subSelectWhere)(phs)(k, v) | ||
: typeof (v || {}).inSelectWithLevels !== "undefined" | ||
? inSelectWithLevels(phs)(k, v) | ||
: typeof (v || {}).json !== "undefined" | ||
? jsonWhere(k, v.json, phs) | ||
: v === null | ||
? `${quote((0, exports.sqlsanitizeAllowDots)(k))} is null` | ||
: k === "not" | ||
? `not (${typeof v === "symbol" ? v.description : phs.push(v)})` | ||
: `${quote((0, exports.sqlsanitizeAllowDots)(k))}=${typeof v === "symbol" ? v.description : phs.push(v)}`; | ||
function isdef(x) { | ||
@@ -267,0 +274,0 @@ return typeof x !== "undefined"; |
@@ -133,2 +133,8 @@ "use strict"; | ||
}); | ||
it("should query not true", () => { | ||
expect(mkWhere({ not: { foo: true } })).toStrictEqual({ | ||
values: [true], | ||
where: 'where not ("foo"=$1)', | ||
}); | ||
}); | ||
it("should query lt/gt", () => { | ||
@@ -337,2 +343,17 @@ expect(mkWhere({ id: { lt: 5 } })).toStrictEqual({ | ||
}); | ||
it("should query and", () => { | ||
expect(mkWhere({ and: [{ id: 5 }, { x: 7 }] })).toStrictEqual({ | ||
values: [5, 7], | ||
where: 'where ("id"=$1 and "x"=$2)', | ||
}); | ||
expect(mkWhere({ | ||
and: [ | ||
{ or: [{ bar: "Zoo" }, { bar: "Baz" }] }, | ||
{ or: [{ foo: false }, { foo: null }] }, | ||
], | ||
})).toStrictEqual({ | ||
values: ["Zoo", "Baz", false], | ||
where: 'where (("bar"=$1 or "bar"=$2) and ("foo"=$3 or "foo" is null))', | ||
}); | ||
}); | ||
}); | ||
@@ -339,0 +360,0 @@ describe("sqlsanitize", () => { |
{ | ||
"name": "@saltcorn/db-common", | ||
"version": "0.9.6-beta.12", | ||
"version": "0.9.6-beta.13", | ||
"description": "Db common structures for Saltcorn, open-source no-code platform", | ||
@@ -5,0 +5,0 @@ "homepage": "https://saltcorn.com", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
113824
1578