diff --git a/lib/datastore.js b/lib/datastore.js index e32e4f3..7141648 100644 --- a/lib/datastore.js +++ b/lib/datastore.js @@ -152,14 +152,26 @@ Datastore.prototype.findOne = function (query, callback) { /** * Persist the whole database + * @param {Array} data Optional data to persist. If not set, we use the database data * @param {Function} cb Optional callback, signature: err */ -Datastore.prototype.persistWholeDatabase = function (cb) { - var callback = cb || function () {} +Datastore.prototype.persistWholeDatabase = function (data, cb) { + var callback , self = this , newContents = ''; - self.data.forEach(function (d) { + if (!data) { + data = self.data; + } + + if (typeof data === 'function') { + cb = data; + data = self.data; + } + + callback = cb || function () {}; + + data.forEach(function (d) { newContents += JSON.stringify(d) + '\n'; }); @@ -167,6 +179,18 @@ Datastore.prototype.persistWholeDatabase = function (cb) { }; +/** + * Update the first doc matching query + * @param {Object} query + * @param {Object} newDoc Will replace the former doc + * @param {Function} cb Optional callback, signature: err, replaced?, newDoc + */ +Datastore.prototype.updateOne = function (query, newDoc, cb) { + var callback = cb || function () {}; + +}; + + var d = new Datastore('workspace/test.db'); @@ -174,7 +198,6 @@ d.loadDatabase(function (err) { console.log(d.data); d.data = [{ff: 'mec'}, {ee: 'test'}]; - d.persistWholeDatabase(); });