viewmodel
Advanced tools
Comparing version 1.2.4 to 1.2.5
@@ -93,2 +93,10 @@ 'use strict'; | ||
/** | ||
* Clears the complete collection... | ||
* @param {Function} callback the function that will be called when this action has finished [optional] | ||
*/ | ||
clear: function (callback) { | ||
implementError(callback); | ||
}, | ||
/** | ||
* NEVER USE THIS FUNCTION!!! ONLY FOR TESTS! | ||
@@ -98,3 +106,3 @@ * clears the complete store... | ||
*/ | ||
clear: function (callback) { | ||
clearAll: function (callback) { | ||
implementError(callback); | ||
@@ -101,0 +109,0 @@ }, |
@@ -326,4 +326,31 @@ 'use strict'; | ||
var self = this; | ||
if (!this.collectionName) { | ||
if (callback) callback(null); | ||
return; | ||
} | ||
var query = new azure.TableQuery(); | ||
this.client.queryEntities(this.collectionName, query, null, function (err, entities) { | ||
if (err) { | ||
if (callback) callback(err); | ||
return; | ||
} | ||
async.each(entities.entries, function (entity, callback) { | ||
self.client.deleteEntity(col, entity, function (error, response) { | ||
if (callback) callback(error); | ||
}); | ||
}, | ||
function (error) { | ||
if (callback) callback(error); | ||
} | ||
); | ||
}); | ||
}, | ||
clearAll: function (callback) { | ||
var self = this; | ||
var query = new azure.TableQuery(); | ||
async.each(collections, function (col, callback) { | ||
@@ -330,0 +357,0 @@ |
@@ -102,3 +102,3 @@ 'use strict'; | ||
emit(key, doc); | ||
split4(item, newI); | ||
@@ -128,3 +128,3 @@ } | ||
emit(key, doc); | ||
split3(item, newI); | ||
@@ -152,3 +152,3 @@ } | ||
emit(key, doc); | ||
split2(item, i); | ||
@@ -376,4 +376,40 @@ } | ||
clear: function (callback) { | ||
if (!this.collectionName) { | ||
if (callback) callback(null); | ||
return; | ||
} | ||
var self = this; | ||
this.db.view('collection/find', { key: { collectionName: this.collectionName } }, function (err, docs) { | ||
if (err) { | ||
if (callback) callback(err); | ||
return; | ||
} | ||
var res = []; | ||
for (var i = 0, len = docs.length; i < len; i++){ | ||
var doc = docs[i].value; | ||
var found = _.find(res, function(r) { | ||
return r.id === doc.id; | ||
}); | ||
if (!found) { | ||
res.push(doc); | ||
} | ||
} | ||
async.each(res, function (d, callback) { | ||
self.db.remove(d._id, d._rev, callback); | ||
}, function (err) { | ||
if (callback) callback(err); | ||
}); | ||
}); | ||
}, | ||
clearAll: function (callback) { | ||
var self = this; | ||
async.each(collections, function (col, callback) { | ||
@@ -380,0 +416,0 @@ self.db.view('collection/find', { key: { collectionName: col } }, function (err, docs) { |
@@ -9,34 +9,6 @@ 'use strict'; | ||
_ = require('lodash'), | ||
sift = require('sift'), | ||
store = {}, | ||
collections = []; | ||
function deepFind (obj, pattern) { | ||
var found; | ||
if (pattern) { | ||
var parts = pattern.split('.'); | ||
found = obj; | ||
for (var i in parts) { | ||
found = found[parts[i]]; | ||
if (_.isArray(found)) { | ||
found = _.filter(found, function (item) { | ||
var deepFound = deepFind(item, parts.slice(i + 1).join('.')); | ||
if (deepFound) { | ||
return true; | ||
} | ||
return false; | ||
}); | ||
break; | ||
} | ||
if (!found) { | ||
break; | ||
} | ||
} | ||
} | ||
return found; | ||
} | ||
function InMemory(options) { | ||
@@ -90,20 +62,3 @@ Repository.call(this, options); | ||
if (!_.isEmpty(query)) { | ||
vms = _.filter(vms, function(vm) { | ||
var keys = _.keys(query); | ||
var values = _.values(query); | ||
var found = false; | ||
for (var i in keys) { | ||
var key = keys[i]; | ||
var deepFound = deepFind(vm, key); | ||
if (_.isArray(deepFound) && deepFound.length > 0) { | ||
found = true; | ||
} else if (deepFound === values[i]) { | ||
found = true; | ||
} else { | ||
found = false; | ||
break; | ||
} | ||
} | ||
return found; | ||
}); | ||
vms = sift(query, vms); | ||
} | ||
@@ -168,2 +123,9 @@ | ||
clear: function (callback) { | ||
if (store[this.collectionName]) { | ||
store[this.collectionName] = {}; | ||
} | ||
if (callback) callback(null); | ||
}, | ||
clearAll: function (callback) { | ||
store = {}; | ||
@@ -170,0 +132,0 @@ collections.forEach(function (col) { |
@@ -237,2 +237,15 @@ 'use strict'; | ||
clear: function (callback) { | ||
if (!this.collection) { | ||
if (callback) callback(null); | ||
return; | ||
} | ||
this.collection.remove({}, { safe: true }, function (err) { | ||
if (callback) { | ||
callback(err); | ||
} | ||
}); | ||
}, | ||
clearAll: function (callback) { | ||
var self = this; | ||
@@ -239,0 +252,0 @@ async.each(collections, function (col, callback) { |
@@ -94,3 +94,3 @@ 'use strict'; | ||
} | ||
self.emit('connect'); | ||
@@ -219,3 +219,3 @@ | ||
this.checkConnection(); | ||
if(!vm.actionOnCommit) return callback(new Error()); | ||
@@ -298,3 +298,3 @@ | ||
} | ||
vm.actionOnCommit = 'update'; | ||
@@ -305,3 +305,3 @@ callback(err, vm); | ||
}); | ||
break; | ||
@@ -326,3 +326,24 @@ default: | ||
clear: function (callback) { | ||
if (!this.prefix) { | ||
if (callback) callback(null); | ||
return; | ||
} | ||
var self = this; | ||
this.client.keys(this.prefix + ':*', function(err, keys) { | ||
if (err) { | ||
if (callback) callback(err); | ||
return | ||
} | ||
async.each(keys, function (key, callback) { | ||
self.client.del(key, callback); | ||
}, function (err) { | ||
if (callback) callback(err); | ||
}); | ||
}); | ||
}, | ||
clearAll: function (callback) { | ||
var self = this; | ||
async.each(collections, function (col, callback) { | ||
@@ -329,0 +350,0 @@ async.parallel([ |
@@ -114,3 +114,3 @@ 'use strict'; | ||
this.checkConnection(); | ||
if(!vm.actionOnCommit) return callback(new Error()); | ||
@@ -175,3 +175,3 @@ | ||
self.client.ensureIndex(self.collectionName, index, options, function(err, indexName) { | ||
self.collection.ensureIndex(index, options, function(err, indexName) { | ||
// nothing todo. | ||
@@ -196,2 +196,15 @@ }); | ||
clear: function (callback) { | ||
if (!this.collection) { | ||
if (callback) callback(null); | ||
return; | ||
} | ||
this.collection.remove({}, { safe: true }, function (err) { | ||
if (callback) { | ||
callback(err); | ||
} | ||
}); | ||
}, | ||
clearAll: function (callback) { | ||
var self = this; | ||
@@ -198,0 +211,0 @@ async.each(collections, function (col, callback) { |
@@ -168,2 +168,5 @@ 'use strict'; | ||
}; | ||
repo.clear = function (callback) { | ||
permissionError(callback); | ||
}; | ||
var orgGet = repo.get; | ||
@@ -170,0 +173,0 @@ repo.get = function (id, callback) { |
{ | ||
"author": "adrai", | ||
"name": "viewmodel", | ||
"version": "1.2.4", | ||
"version": "1.2.5", | ||
"private": false, | ||
@@ -19,2 +19,3 @@ "main": "index.js", | ||
"node-uuid": "1.4.1", | ||
"sift": "0.2.3", | ||
"tolerance": "1.0.0" | ||
@@ -21,0 +22,0 @@ }, |
@@ -37,3 +37,3 @@ # Introduction | ||
timeout: 10000 // optional | ||
}, | ||
}, | ||
function(err, repository) { | ||
@@ -157,3 +157,12 @@ if(err) { | ||
## Clear a "collection" (only in write mode) | ||
dummyRepo.clear(function(err) { | ||
if(err) { | ||
console.log('ohhh :-('); | ||
return; | ||
} | ||
}); | ||
# Implementation differences | ||
@@ -215,3 +224,3 @@ | ||
Copyright (c) 2014 Adriano Raiano | ||
Copyright (c) 2015 Adriano Raiano | ||
@@ -218,0 +227,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy |
@@ -0,1 +1,4 @@ | ||
## [v1.2.5](https://github.com/adrai/node-viewmodel/compare/v1.2.4...v1.2.5) | ||
- added clear functionality to clear a collection | ||
## [v1.2.4](https://github.com/adrai/node-viewmodel/compare/v1.2.3...v1.2.4) | ||
@@ -2,0 +5,0 @@ - fix date issue for azure-table [#8](https://github.com/adrai/node-viewmodel/pull/8) thanks to [sbiaudet](https://github.com/sbiaudet) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
68290
1865
241
7
+ Addedsift@0.2.3
+ Addedsift@0.2.3(transitive)