Skip to content
This repository was archived by the owner on Aug 13, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
language: node_js
node_js:
- "0.11"
- "0.10"
- "0.8"
23 changes: 13 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module.exports = (function () {
var data = { };
var schema = { };
var counters = { };
var collections = { };

var adapter = {

Expand All @@ -28,37 +29,35 @@ module.exports = (function () {

// How this adapter should be synced
migrate: 'alter',

// Default configuration for collections
// Allow a schemaless datastore
defaults: {
schema: false
},

registerCollection: function (collection, cb) {
// Save reference to collection so we have it
schema[collection.identity] = collection;
collection[collection.identity] = collection;
cb();
},

// Return attributes
describe: function (collectionName, cb) {
cb(null, schema[collectionName].attributes);
cb(null, schema[collectionName]);
},

// Adapters are not responsible for checking for existence of the collection
define: function (collectionName, definition, cb) {

data[collectionName] = [];
counters[collectionName] = {};
schema[collectionName].attributes = _.clone(definition);
schema[collectionName] = _.clone(definition);

cb(null, schema[collectionName].attributes);
cb(null, schema[collectionName]);
},

drop: function (collectionName, cb) {

delete data[collectionName];
delete schema[collectionName].attributes;
delete schema[collectionName];
delete counters[collectionName];

cb();
Expand Down Expand Up @@ -239,9 +238,9 @@ module.exports = (function () {

create: function (collectionName, values, cb) {

for (var attrName in schema[collectionName].attributes) {
for (var attrName in schema[collectionName]) {

var attrDef = schema[collectionName].attributes[attrName];
var attrDef = schema[collectionName][attrName];

if (attrDef.unique) {
for (var index in data[collectionName]) {
Expand Down Expand Up @@ -273,6 +272,10 @@ module.exports = (function () {
}
}

if(!data[collectionName]) {
data[collectionName] = [];
}

data[collectionName].push(values);

cb(null, values);
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sails-memory",
"version": "0.9.1",
"version": "0.9.3",
"description": "Non-persistent, in-memory adapter for Sails.js / Waterline",
"main": "index.js",
"scripts": {
Expand All @@ -22,7 +22,7 @@
"license": "MIT",
"readmeFilename": "README.md",
"dependencies": {
"lodash": "1.2.1",
"lodash": "~2.4.0",
"waterline-criteria": "~0.9.1"
},
"devDependencies": {
Expand Down