Comparing version 0.1.2 to 0.1.3
@@ -5,2 +5,9 @@ # Changelog | ||
## [0.1.3](https://gitlab.com/monstrous/monstrous/compare/v0.1.2...v0.1.3) (2023-03-06) | ||
### Bug Fixes | ||
* compile exprs in predicate-tree mutators ([58920bf](https://gitlab.com/monstrous/monstrous/commit/58920bfe45bc346f7443ae4b5f984d787e43f7ba)) | ||
## [0.1.2](https://gitlab.com/monstrous/monstrous/compare/v0.1.1...v0.1.2) (2023-02-19) | ||
@@ -7,0 +14,0 @@ |
@@ -8,5 +8,15 @@ import pgp from 'pg-promise'; | ||
const non_value_rhs = function (rhs, param_idx) { | ||
}; | ||
const mutators = { | ||
identity: (lhs, op, rhs, param_idx) => { | ||
if (param_idx === undefined) { | ||
// run as a check in other mutators for right-hand sides other than criteria | ||
// object values | ||
non_value: (lhs, op, rhs, param_idx) => { | ||
// TODO handle Tuples | ||
if (rhs instanceof Expr) { | ||
return { | ||
sql: pgp.as.format(`${lhs} ${op} ${rhs.compile()}`) | ||
} | ||
} else if (param_idx === undefined) { | ||
// column-to-column comparison | ||
@@ -18,2 +28,10 @@ return { | ||
return null; | ||
}, | ||
// the default: don't do anything at all to the rhs, return it as-is | ||
identity: (lhs, op, rhs, param_idx) => { | ||
const nv = mutators.non_value(lhs, op, rhs, param_idx); | ||
if (nv) return nv; | ||
return { | ||
@@ -24,2 +42,5 @@ sql: pgp.as.format(`${lhs} ${op} $${param_idx}`), | ||
}, | ||
// special equality cases transform the operation and right-hand side: | ||
// - `is` for null and boolean values | ||
// - `in` for array values | ||
equality: (lhs, op, rhs, param_idx) => { | ||
@@ -31,9 +52,6 @@ if (op === '=' && (rhs === null || Object.prototype.toString.call(rhs) === '[object Boolean]')) { | ||
if (param_idx === undefined) { | ||
// column-to-column comparison | ||
return { | ||
sql: pgp.as.format(`${lhs} ${op} ${rhs}`) | ||
}; | ||
} | ||
const nv = mutators.non_value(lhs, op, rhs, param_idx); | ||
if (nv) return nv; | ||
if (Array.isArray(rhs)) { | ||
@@ -40,0 +58,0 @@ // build an `in` |
@@ -72,2 +72,6 @@ import pgp from 'pg-promise'; | ||
for (const qualified of (Array.isArray(val) ? val : [val])) { | ||
if (qualified === undefined) { | ||
throw new Error('undefined $key in projection definition; check your column names'); | ||
} | ||
const name = unquote(qualified.split('.').pop()); | ||
@@ -74,0 +78,0 @@ created.#key.push(name); |
{ | ||
"name": "monstrous", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "a lightweight SQL composer for Node.js and PostgreSQL", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -10,5 +10,5 @@ # monstrous | ||
db.libraries | ||
.join(db.holdings, db.$join.left) // implicit join on foreign key holdings.library_id | ||
.join(db.books, db.$join.left) // implicit join on foreign key holdings.book_id | ||
.join(db.authors, {[db.authors.$id]: db.books.$author_id}) | ||
.join(db.holdings) // implicit join on foreign key holdings.library_id | ||
.join(db.books) // implicit join on foreign key holdings.book_id | ||
.join(db.authors, db.$join.left, {[db.authors.$id]: db.books.$author_id}) | ||
.filter({ | ||
@@ -15,0 +15,0 @@ [db.libraries.$postcode]: '12345', |
85671
1783