Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Lazy-create any needed collections for the in-memory adapter

  • Loading branch information...
commit 6925ee2ebf2ed744a4b99d84aedff0bfdd61b7ef 1 parent c26238f
mde authored
Showing with 27 additions and 1 deletion.
  1. +27 −1 lib/adapters/memory/index.js
View
28 lib/adapters/memory/index.js
@@ -38,12 +38,20 @@ utils.mixin(Adapter.prototype, new (function () {
, id = query.byId
, conditions
, sort
- , items = _data[key]
+ , items
, item
, data
, val
, filter
, res = [];
+
+ // Lazy-create the collection
+ if (!_data[key]) {
+ _data[key] = {};
+ }
+
+ items = _data[key];
+
if (id) {
item = _data[key][id];
callback(null, item);
@@ -97,6 +105,12 @@ utils.mixin(Adapter.prototype, new (function () {
var key = query.model.modelName
, id = query.byId
, ids;
+
+ // Lazy-create the collection
+ if (!_data[key]) {
+ _data[key] = {};
+ }
+
if (id) {
ids = [id];
}
@@ -135,6 +149,12 @@ utils.mixin(Adapter.prototype, new (function () {
var key = query.model.modelName
, id = query.byId
, ids;
+
+ // Lazy-create the collection
+ if (!_data[key]) {
+ _data[key] = {};
+ }
+
if (id) {
ids = [id];
}
@@ -164,6 +184,12 @@ utils.mixin(Adapter.prototype, new (function () {
this.insert = function (data, opts, callback) {
var items = Array.isArray(data) ? data.slice() : [data]
, key = items[0].type;
+
+ // Lazy-create the collection
+ if (!_data[key]) {
+ _data[key] = {};
+ }
+
items.forEach(function (item) {
var id = utils.string.uuid();
item.id = id;
Please sign in to comment.
Something went wrong with that request. Please try again.