From c816affc684b8bfcfe39717e76962cf3b17ccf1d Mon Sep 17 00:00:00 2001 From: Louis Chatriot Date: Sat, 25 May 2013 18:21:43 +0200 Subject: [PATCH] Removed useless persistWholeDatabase --- lib/datastore.js | 29 ----------------------------- lib/model.js | 3 +++ 2 files changed, 3 insertions(+), 29 deletions(-) diff --git a/lib/datastore.js b/lib/datastore.js index 33c1992..77b7923 100644 --- a/lib/datastore.js +++ b/lib/datastore.js @@ -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) * @param {Array} newDocs Can be empty if no doc was updated/removed diff --git a/lib/model.js b/lib/model.js index ef19df8..e8819c7 100644 --- a/lib/model.js +++ b/lib/model.js @@ -55,6 +55,9 @@ function checkObject (obj) { /** * Serialize an object to be persisted to a one-line string + * For serialization/deserialization, we use the native JSON parser and not eval or Function + * That gives us less freedom but data entered in the database may come from users + * so eval and the like are not safe * Accepted primitive types: Number, String, Boolean, Date, null * Accepted secondary types: Objects, Arrays */