Comparing version 4.1.0 to 4.2.0
@@ -54,3 +54,3 @@ # Options | ||
* `pk` (for "primary key") specifies the field in the resultset which uniquely identifies the entity represented by this schema. | ||
* `columns` is a map of fields in the resultset (keys) to fields in the output entity (values). | ||
* `columns` is either a map of fields in the resultset (keys) to fields in the output entity (values), or an array of field names if they do not need to be transformed. | ||
* `array` is only usable on schemas nested at least one level deep. If `true`, the entities this schema represents are considered a collection instead of a nested object. | ||
@@ -64,6 +64,3 @@ | ||
pk: 'user_id', | ||
columns: { | ||
user_id: 'id', | ||
username: 'username' | ||
}, | ||
columns: ['user_id', 'username'], | ||
tests: { | ||
@@ -81,7 +78,17 @@ pk: 'test_id', | ||
will generate results in this format: | ||
will transform this recordset: | ||
```javascript | ||
[ | ||
{user_id: 1, username: 'alice', test_id: 1, name: 'first'}, | ||
{user_id: 1, username: 'alice', test_id: 2, name: 'second'}, | ||
{user_id: 2, username: 'bob', test_id: 3, name: 'third'}, | ||
] | ||
``` | ||
into this: | ||
```javascript | ||
[{ | ||
id: 1, | ||
user_id: 1, | ||
username: 'alice', | ||
@@ -96,3 +103,3 @@ tests: [{ | ||
}, { | ||
id: 2, | ||
user_id: 2, | ||
username: 'bob', | ||
@@ -99,0 +106,0 @@ tests: [{ |
@@ -16,4 +16,5 @@ 'use strict'; | ||
* uniquely identifies a single record. | ||
* @param {Object} schema.colums - A map of field names in the result set to | ||
* keys of an output object. | ||
* @param {Object|Array} schema.columns - A map of field names in the result set | ||
* to keys of an output object, or an array of field names if no transformation | ||
* of names is desired. | ||
* @param {Boolean} schema.array - When true, entities built with this schema | ||
@@ -53,7 +54,14 @@ * are coerced into arrays of entities. This is only valid for nested schemas. | ||
// the columns object maps field names in the row to object key names | ||
_.map(objSchema.columns, (val, key) => { | ||
obj[id][val] = row[key]; | ||
}); | ||
let mapper; | ||
if (_.isArray(objSchema.columns)) { | ||
// columns is just a list of field names | ||
mapper = val => obj[id][val] = row[val]; | ||
} else { | ||
// the columns object maps field names in the row to object key names | ||
mapper = (val, key) => obj[id][val] = row[key]; | ||
} | ||
_.map(objSchema.columns, mapper); | ||
Object.keys(objSchema).forEach(function (c) { | ||
@@ -60,0 +68,0 @@ switch (c) { |
@@ -5,2 +5,13 @@ 'use strict'; | ||
/** | ||
* Assembles a parameter list for a prepared statement from a list of records | ||
* being inserted or updated. Parameter list generation for WHERE clauses in | ||
* all statements is handled in {@linkcode module:where}. | ||
* | ||
* @module util/prepareParams | ||
* @param {Array} fields - A list of fields to pick from each record. | ||
* @param {Array} records - A list of records. | ||
* @return {Array} An array containing the values of each key from each record, | ||
* or undefined if the record does not contain the key. | ||
*/ | ||
exports = module.exports = (fields, records) => _.reduce(records, (params, r) => { | ||
@@ -10,8 +21,4 @@ return params.concat(fields.map(key => { | ||
if (_.isArray(val) && val.length === 0) { | ||
return '{}'; // legacy syntax is easier than introspecting+storing types | ||
} | ||
return val; | ||
})); | ||
}, []); |
{ | ||
"name": "massive", | ||
"version": "4.1.0", | ||
"version": "4.2.0", | ||
"description": "A small query tool for Postgres that embraces json and makes life simpler", | ||
@@ -51,4 +51,3 @@ "homepage": "https://dmfay.github.io/massive-js/", | ||
"lodash": "~4.17.4", | ||
"mz": "~2.7.0", | ||
"pg-promise": "~6.7.0", | ||
"pg-promise": "~6.7.1", | ||
"pg-query-stream": "~1.0.0" | ||
@@ -59,5 +58,5 @@ }, | ||
"chai-as-promised": "~7.1.1", | ||
"co-mocha": "~1.1.3", | ||
"co-mocha": "~1.2.0", | ||
"coveralls": "~2.13.1", | ||
"eslint": "~4.7.0", | ||
"eslint": "~4.7.1", | ||
"jsdoc": "^3.5.4", | ||
@@ -64,0 +63,0 @@ "mocha": "~3.5.1", |
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
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
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
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
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
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
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
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
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
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
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
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
Sorry, the diff of this file is not supported yet
1534525
5
120
2412
- Removedmz@~2.7.0
- Removedany-promise@1.3.0(transitive)
- Removedmz@2.7.0(transitive)
- Removedobject-assign@4.1.1(transitive)
- Removedthenify@3.3.1(transitive)
- Removedthenify-all@1.6.0(transitive)
Updatedpg-promise@~6.7.1