|
|
@ -171,35 +171,6 @@ 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 (data, cb) { |
|
|
|
|
|
|
|
var callback |
|
|
|
|
|
|
|
, self = this |
|
|
|
|
|
|
|
, newContents = ''; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!data) { |
|
|
|
|
|
|
|
data = self.data; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (typeof data === 'function') { |
|
|
|
|
|
|
|
cb = data; |
|
|
|
|
|
|
|
data = self.data; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
callback = cb || function () {}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data.forEach(function (d) { |
|
|
|
|
|
|
|
newContents += model.serialize(d) + '\n'; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fs.writeFile(self.filename, newContents, 'utf8', callback); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Persist new state for the given newDocs (can be update or removal) |
|
|
|
* Persist new state for the given newDocs (can be update or removal) |
|
|
|
* @param {Array} newDocs Can be empty if no doc was updated/removed |
|
|
|
* @param {Array} newDocs Can be empty if no doc was updated/removed |
|
|
|