Comparing version 6.8.0 to 6.9.0
@@ -5,2 +5,10 @@ # Changelog | ||
## [6.9.0](https://gitlab.com/dmfay/massive-js/compare/v6.8.0...v6.9.0) (2021-05-13) | ||
### Features | ||
* $set fields to raw SQL expressions in update ([64fab99](https://gitlab.com/dmfay/massive-js/commit/64fab99a9fd1eca1ab8e88700306d4bb3777a24e)) | ||
* support $and and $or criteria keys ([211f11e](https://gitlab.com/dmfay/massive-js/commit/211f11e75f5903b74da2fbc7f362c3d6cc9ef4fd)) | ||
## [6.8.0](https://gitlab.com/dmfay/massive-js/compare/v6.7.1...v6.8.0) (2021-04-24) | ||
@@ -7,0 +15,0 @@ |
@@ -265,3 +265,3 @@ 'use strict'; | ||
* @param {Object} criteria - The criteria object representing the JOIN | ||
* conditions. May be nested with `or`, just as ordinary criteria objects. | ||
* conditions. May be nested with `$or`, just as ordinary criteria objects. | ||
* @param {Number} offset - Offset prepared statement parameter ordinals | ||
@@ -294,3 +294,3 @@ * @param {Symbol} kind - forJoin, forWhere, or forDoc. | ||
* @param {Object} criteria - The criteria object representing the JOIN | ||
* conditions. May be nested with `or`, just as ordinary criteria objects. | ||
* conditions. May be nested with `$or`, just as ordinary criteria objects. | ||
* @param {Number} offset - Offset prepared statement parameter ordinals | ||
@@ -303,3 +303,5 @@ * @param {Symbol} kind - forJoin, forWhere, or forDoc. | ||
return _.reduce(criteria, (conjunction, val, key) => { | ||
if (key === 'or') { | ||
// TODO un-$ed names are officially deprecated but may or may not ever be | ||
// practical to remove | ||
if (['$or', 'or'].indexOf(key) > -1) { | ||
const disjunction = this.disjoin(val, conjunction.offset + conjunction.params.length, kind, ...args); | ||
@@ -311,3 +313,3 @@ | ||
return conjunction; | ||
} else if (key === 'and') { | ||
} else if (['$and', 'and'].indexOf(key) > -1) { | ||
const predicates = []; // track subconjunction predicates separately since they're grouped together | ||
@@ -396,5 +398,5 @@ | ||
* including operation eg 'my_field <>') to the parameter values. Predicates | ||
* generated from a criteria object are joined together with `and`; an `or` key | ||
* denotes an array of nested criteria objects, the collected predicates from | ||
* each of which are parenthesized and joined with `or`. | ||
* generated from a criteria object are joined together with `$and`; an `$or` | ||
* key denotes an array of nested criteria objects, the collected predicates | ||
* from each of which are parenthesized and joined with `$or`. | ||
* @param {Number} offset - Added to the token index value in the prepared | ||
@@ -401,0 +403,0 @@ * statement (with offset 0, parameters will start $1, $2, $3). |
@@ -21,7 +21,17 @@ 'use strict'; | ||
changes = _.pick(changes, source.columnNames); | ||
changes = _.pick(changes, [...source.columnNames, '$set']); | ||
this.changes = _.reduce(changes, (acc, value, key) => { | ||
acc.push(`"${key}" = $${++offset}`); | ||
if (key === '$set' && _.isObject(value)) { | ||
Object.entries(value).forEach(([setKey, setValue]) => { | ||
if (Object.keys(changes).includes(setKey)) { | ||
throw new Error(`The key '${setKey}' may not be defined in both the change map and the $set map.`); | ||
} | ||
acc.push(`"${setKey}" = ${setValue}`); | ||
}); | ||
} else { | ||
acc.push(`"${key}" = $${++offset}`); | ||
} | ||
return acc; | ||
@@ -28,0 +38,0 @@ }, []); |
{ | ||
"name": "massive", | ||
"version": "6.8.0", | ||
"version": "6.9.0", | ||
"description": "A small query tool for Postgres that embraces json and makes life simpler", | ||
@@ -52,17 +52,17 @@ "homepage": "https://massivejs.org", | ||
"dependencies": { | ||
"commander": "7.1.0", | ||
"glob": "7.1.6", | ||
"commander": "7.2.0", | ||
"glob": "7.1.7", | ||
"lodash": "4.17.21", | ||
"murmurhash": "1.0.0", | ||
"pg-promise": "^10.9.4", | ||
"pg-query-stream": "^4.0.0" | ||
"pg-promise": "^10.10.2", | ||
"pg-query-stream": "^4.1.0" | ||
}, | ||
"devDependencies": { | ||
"chai": "4.3.0", | ||
"chai": "4.3.4", | ||
"chai-as-promised": "7.1.1", | ||
"coveralls": "3.1.0", | ||
"eslint": "7.20.0", | ||
"mocha": "8.3.0", | ||
"eslint": "7.26.0", | ||
"mocha": "8.4.0", | ||
"nyc": "15.1.0", | ||
"standard-version": "9.1.1" | ||
"standard-version": "9.3.0" | ||
}, | ||
@@ -69,0 +69,0 @@ "repository": { |
188213
3097
+ Addedcommander@7.2.0(transitive)
+ Addedglob@7.1.7(transitive)
- Removedcommander@7.1.0(transitive)
- Removedglob@7.1.6(transitive)
Updatedcommander@7.2.0
Updatedglob@7.1.7
Updatedpg-promise@^10.10.2
Updatedpg-query-stream@^4.1.0