waterline-dirty
Advanced tools
Comparing version 0.0.03 to 0.0.04
@@ -77,3 +77,2 @@ /*--------------------------------------------------------------- | ||
statusDb[collectionName] = (schema && schema.autoIncrement) ? schema : {autoIncrement: 1}; | ||
// console.log("AI for "+collectionName+" loaded from disk as::",statusDb[collectionName], "schema:",schema); | ||
cb(); | ||
@@ -88,3 +87,2 @@ }, | ||
// (this is done so that the auto-increment counter can be "ressurected" when the adapter is restarted from disk) | ||
// console.log("******** Wrote to "+collectionName+":: AI => ", statusDb[collectionName].autoIncrement); | ||
var schema = _.extend(this.db.get(this.config.schemaPrefix + collectionName),{ | ||
@@ -198,6 +196,7 @@ autoIncrement: statusDb[collectionName].autoIncrement | ||
var dataKey = this.config.dataPrefix + collectionName; | ||
var data = this.db.get(dataKey); | ||
var data = this.db.get(dataKey) || []; | ||
// Query and return result set using criteria | ||
cb(null, applyFilter(data, criteria)); | ||
var filteredData = applyFilter(data, criteria); | ||
cb(null, filteredData); | ||
}, | ||
@@ -326,6 +325,5 @@ | ||
// By default, treat entries as AND | ||
for(var key in criteria) { | ||
if(!matchItem(model, key, criteria[key])) return false; | ||
} | ||
return true; | ||
return _.all(criteria,function(criterion,key) { | ||
return matchItem(model, key, criterion); | ||
}); | ||
} | ||
@@ -352,4 +350,4 @@ | ||
for(var key in criteria) { | ||
// Make attribute names case insensitive unless overridden in config | ||
if(!adapter.config.attributesCaseSensitive) key = key.toLowerCase(); | ||
// TODO: Make attribute names case insensitive unless overridden in config | ||
// if(!adapter.config.attributesCaseSensitive) key = key.toLowerCase(); | ||
@@ -369,5 +367,6 @@ // Check that criterion attribute and is at least similar to the model's value for that attr | ||
function matchItem(model, key, criterion) { | ||
// Make attribute names case insensitive unless overridden in config | ||
if(!adapter.config.attributesCaseSensitive) key = key.toLowerCase(); | ||
// TODO: Make attribute names case insensitive unless overridden in config | ||
// if(!adapter.config.attributesCaseSensitive) key = key.toLowerCase(); | ||
if(key.toLowerCase() === 'or') { | ||
@@ -387,39 +386,15 @@ return matchOr(model, criterion); | ||
} | ||
// ensure the key attr exists in model | ||
else if (_.isUndefined(model[key])) { | ||
return false; | ||
} | ||
// TODO: IN query | ||
// else if(model[key] && _.isObject(model[key])) { | ||
// var inKey = 'in'; | ||
// if (model[key]['IN']) inKey = 'IN'; | ||
// if (!_.isArray(model[key][inKey])) throw new Error('Incorrect usage of IN query.'); | ||
// _.any(model[key][inKey], function (item) { | ||
// return item === criterion[]; | ||
// }); | ||
// return matchIn(model[key], criterion); | ||
// } | ||
// Otherwise this key is an attribute name: ensure it exists and matches | ||
else if(!model[key] || (model[key] !== criterion)) { | ||
// ensure the key attr matches model attr in model | ||
else if((model[key] !== criterion)) { | ||
return false; | ||
} | ||
// Otherwise this is a match | ||
return true; | ||
} | ||
// Number of miliseconds since the Unix epoch Jan 1st, 1970 | ||
function epoch() { | ||
return(new Date()).getTime(); | ||
} | ||
// Return the oldest lock in the collection | ||
function getOldest(locks) { | ||
var currentLock; | ||
_.each(locks, function(lock) { | ||
if(!currentLock) currentLock = lock; | ||
else if(lock.timestamp < currentLock.timestamp) currentLock = lock; | ||
}); | ||
return currentLock; | ||
} | ||
// Public API | ||
@@ -426,0 +401,0 @@ // * NOTE: The public API for adapters is a function that can be passed a set of options |
{ | ||
"name": "waterline-dirty", | ||
"version": "0.0.03", | ||
"version": "0.0.04", | ||
"description": "Waterline adapter for felixge's node-dirty", | ||
@@ -5,0 +5,0 @@ "main": "DirtyAdapter.js", |
13838
316