diff --git a/lib/adapters/memory.js b/lib/adapters/memory.js index 52c0c3b1..f1456f30 100644 --- a/lib/adapters/memory.js +++ b/lib/adapters/memory.js @@ -70,7 +70,7 @@ Memory.prototype.exists = function exists(model, id, callback) { Memory.prototype.find = function find(model, id, callback) { process.nextTick(function () { - callback(null, id in this.cache[model] && JSON.parse(this.cache[model][id])); + callback(null, id in this.cache[model] && this.fromDb(model, this.cache[model][id])); }.bind(this)); }; @@ -79,10 +79,34 @@ Memory.prototype.destroy = function destroy(model, id, callback) { process.nextTick(callback); }; +Memory.prototype.fromDb = function(model, data) { + if (!data) return null; + data = JSON.parse(data); + var props = this._models[model].properties; + Object.keys(data).forEach(function (key) { + var val = data[key]; + if (typeof val === 'undefined' || val === null) { + return; + } + if (props[key]) { + switch(props[key].type.name) { + case 'Date': + val = new Date(val.toString().replace(/GMT.*$/, 'GMT')); + break; + case 'Boolean': + val = new Boolean(val); + break; + } + } + data[key] = val; + }); + return data; +}; + Memory.prototype.all = function all(model, filter, callback) { var self = this; var nodes = Object.keys(this.cache[model]).map(function (key) { - return JSON.parse(this.cache[model][key]); + return this.fromDb(model, this.cache[model][key]); }.bind(this)); if (filter) {