From a20297451b88c604b16a35223be4b25528713c6d Mon Sep 17 00:00:00 2001 From: Sean Fridman Date: Sat, 11 Apr 2015 01:36:09 -0400 Subject: Implement FSDB.updateBatch and OKResource.updateBatch --- app/node_modules/okdb/index.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'app/node_modules/okdb/index.js') diff --git a/app/node_modules/okdb/index.js b/app/node_modules/okdb/index.js index c00087c..ffe3ff1 100644 --- a/app/node_modules/okdb/index.js +++ b/app/node_modules/okdb/index.js @@ -101,6 +101,26 @@ FSDB.prototype.update = function(collection, id, data) { } }; +/** + * TODO Should be atomic ¯\_(ツ)_/¯ + */ +FSDB.prototype.updateBatch = function(collection, ids, datas) { + var schema = this._schemas[collection]; + if (!schema) + return resolve(null, new Error('No such collection type')); + if (!ids || !ids.length || !datas || !datas.length || + ids.length !== datas.length) { + return resolve(null, new Error('Bad input')); + } + + var doc = this._db(collection); + var results = ids.map(function(id, i) { + return doc.chain().find(getQuery(schema, id)).assign(datas[i]).value(); + }); + + return resolve(results); +}; + FSDB.prototype.remove = function(collection, id) { var schema = this._schemas[collection]; if (!schema) -- cgit v1.2.3-70-g09d2