@saltcorn/db-common
Advanced tools
Comparing version 1.1.2-beta.9 to 1.1.2-beta.10
@@ -249,31 +249,40 @@ "use strict"; | ||
.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 === "_false" && v | ||
? "FALSE" | ||
: 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) { | ||
@@ -419,3 +428,5 @@ return typeof x !== "undefined"; | ||
? `order by ${getDistanceOrder(selopts.orderBy.distance)}` | ||
: selopts.orderBy && typeof selopts.orderBy === "string" && selopts.nocase | ||
: selopts.orderBy && | ||
typeof selopts.orderBy === "string" && | ||
selopts.nocase | ||
? `order by lower(${quote((0, exports.sqlsanitizeAllowDots)(selopts.orderBy))})${selopts.orderDesc ? " DESC" : ""}` | ||
@@ -455,2 +466,5 @@ : selopts.orderBy && typeof selopts.orderBy === "string" | ||
} | ||
else if (k === "eq") { | ||
whereObj[k] = inputWhere[k]; // TODO check for fieldnames | ||
} | ||
else | ||
@@ -457,0 +471,0 @@ whereObj[`${tablePrefix}."${k}"`] = inputWhere[k]; |
@@ -357,2 +357,20 @@ "use strict"; | ||
}); | ||
it("should false", () => { | ||
expect(mkWhere({ _false: true })).toStrictEqual({ | ||
values: [], | ||
where: "where FALSE", | ||
}); | ||
}); | ||
it("equate strings", () => { | ||
expect(mkWhere({ eq: ["ALL", "ALL"] })).toStrictEqual({ | ||
values: ["ALL", "ALL"], | ||
where: "where $1::text=$2::text", | ||
}); | ||
}); | ||
it("equate strings in or", () => { | ||
expect(mkWhere({ or: [{ eq: ["ALL", Symbol("name")] }, { eq: ["ALL", "ALL"] }] })).toStrictEqual({ | ||
values: ["ALL", "ALL", "ALL"], | ||
where: 'where ($1::text="name" or $2::text=$3::text)', | ||
}); | ||
}); | ||
}); | ||
@@ -359,0 +377,0 @@ describe("sqlsanitize", () => { |
{ | ||
"name": "@saltcorn/db-common", | ||
"version": "1.1.2-beta.9", | ||
"version": "1.1.2-beta.10", | ||
"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
118834
1633