viewmodel
Advanced tools
Comparing version 1.1.6 to 1.1.7
@@ -93,2 +93,11 @@ 'use strict'; | ||
/** | ||
* NEVER USE THIS FUNCTION!!! ONLY FOR TESTS! | ||
* clears the complete store... | ||
* @param {Function} callback the function that will be called when this action has finished [optional] | ||
*/ | ||
clear: function (callback) { | ||
implementError(callback); | ||
}, | ||
/** | ||
* Use this function to extend this repository with the appropriate collectionName and perhaps other stuff. | ||
@@ -95,0 +104,0 @@ * @param {Object} obj The object that should be extended. |
@@ -8,3 +8,5 @@ 'use strict'; | ||
cradle = require('cradle'), | ||
_ = require('lodash'); | ||
async = require('async'), | ||
_ = require('lodash'), | ||
collections = []; | ||
@@ -17,3 +19,3 @@ function Couch (options) { | ||
port: 5984, | ||
dbName: 'context', | ||
dbName: 'context' | ||
}; | ||
@@ -364,2 +366,38 @@ | ||
}, | ||
checkConnection: function() { | ||
if (collections.indexOf(this.collectionName) < 0) { | ||
collections.push(this.collectionName) | ||
} | ||
}, | ||
clear: function (callback) { | ||
var self = this; | ||
async.each(collections, function (col, callback) { | ||
self.db.view('collection/find', { key: { collectionName: col } }, function (err, docs) { | ||
if (err) { | ||
return callback(err); | ||
} | ||
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); | ||
}, callback); | ||
}); | ||
}, callback); | ||
} | ||
@@ -366,0 +404,0 @@ |
@@ -9,3 +9,4 @@ 'use strict'; | ||
_ = require('lodash'), | ||
store = {}; | ||
store = {}, | ||
collections = []; | ||
@@ -157,2 +158,18 @@ function deepFind (obj, pattern) { | ||
} | ||
}, | ||
checkConnection: function() { | ||
if (collections.indexOf(this.collectionName) < 0) { | ||
collections.push(this.collectionName) | ||
} | ||
}, | ||
clear: function (callback) { | ||
store = {}; | ||
collections.forEach(function (col) { | ||
if (store[col]) { | ||
delete store[col]; | ||
} | ||
}); | ||
if (callback) callback(null); | ||
} | ||
@@ -159,0 +176,0 @@ |
@@ -9,3 +9,5 @@ 'use strict'; | ||
ObjectID = mongo.BSONPure.ObjectID, | ||
_ = require('lodash'); | ||
_ = require('lodash'), | ||
async = require('async'), | ||
collections = []; | ||
@@ -227,4 +229,15 @@ function Mongo (options) { | ||
if (collections.indexOf(this.collectionName) < 0) { | ||
collections.push(this.collectionName) | ||
} | ||
this.collection = new mongo.Collection(this.client, this.collectionName); | ||
this.ensureIndexes(); | ||
}, | ||
clear: function (callback) { | ||
var self = this; | ||
async.each(collections, function (col, callback) { | ||
(new mongo.Collection(self.client, col)).remove({}, { safe: true }, callback); | ||
}, callback); | ||
} | ||
@@ -231,0 +244,0 @@ |
@@ -11,3 +11,4 @@ 'use strict'; | ||
async = require('async'), | ||
_ = require('lodash'); | ||
_ = require('lodash'), | ||
collections = []; | ||
@@ -314,4 +315,30 @@ function Redis (options) { | ||
} | ||
if (collections.indexOf(this.collectionName) < 0) { | ||
collections.push(this.collectionName) | ||
} | ||
this.prefix = this.collectionName; | ||
}, | ||
clear: function (callback) { | ||
var self = this; | ||
async.each(collections, function (col, callback) { | ||
async.parallel([ | ||
function (callback) { | ||
self.client.del('nextItemId:' + col, callback); | ||
}, | ||
function (callback) { | ||
self.client.keys(col + ':*', function(err, keys) { | ||
if (err) { | ||
return callback(err); | ||
} | ||
async.each(keys, function (key, callback) { | ||
self.client.del(key, callback); | ||
}, callback); | ||
}); | ||
} | ||
], callback); | ||
}, function (err) { | ||
if (callback) callback(err); | ||
}); | ||
} | ||
@@ -318,0 +345,0 @@ |
@@ -11,3 +11,5 @@ 'use strict'; | ||
ObjectID = tingodb.ObjectID, | ||
_ = require('lodash'); | ||
_ = require('lodash'), | ||
async = require('async'), | ||
collections = []; | ||
@@ -154,6 +156,28 @@ function Tingo (options) { | ||
} | ||
}, | ||
ensureIndexes: function() { | ||
var self = this; | ||
if (!this.collectionName || !this.indexes) return; | ||
this.indexes.forEach(function(index) { | ||
var options; | ||
index = index.index ? index.index : index; | ||
options = index.options ? index.options : {}; | ||
if (typeof index === 'string') { | ||
var key = index; | ||
index = {}; | ||
index[key] = 1; | ||
} | ||
self.client.ensureIndex(self.collectionName, index, options, function(err, indexName) { | ||
// nothing todo. | ||
}); | ||
}); | ||
}, | ||
checkConnection: function(callback) { | ||
checkConnection: function() { | ||
if (this.collection) { | ||
@@ -163,3 +187,15 @@ return; | ||
if (collections.indexOf(this.collectionName) < 0) { | ||
collections.push(this.collectionName) | ||
} | ||
this.collection = this.db.createCollection(this.collectionName + '.tingo'); | ||
this.ensureIndexes(); | ||
}, | ||
clear: function (callback) { | ||
var self = this; | ||
async.each(collections, function (col, callback) { | ||
self.db.createCollection(col + '.tingo').remove({}, { safe: true }, callback); | ||
}, callback); | ||
} | ||
@@ -166,0 +202,0 @@ |
{ | ||
"author": "adrai", | ||
"name": "viewmodel", | ||
"version": "1.1.6", | ||
"version": "1.1.7", | ||
"private": false, | ||
@@ -6,0 +6,0 @@ "main": "index.js", |
@@ -1,30 +0,33 @@ | ||
#### v1.1.6 | ||
- Fix undefined repository test in ViewModel constructor [#4](https://github.com/adrai/node-viewmodel/pull/4) thanks to [sbiaudet](https://github.com/sbiaudet) | ||
## v1.1.7 | ||
- added clear function (only for testing) | ||
#### v1.1.5 | ||
## v1.1.6 | ||
- fix undefined repository test in ViewModel constructor [#4](https://github.com/adrai/node-viewmodel/pull/4) thanks to [sbiaudet](https://github.com/sbiaudet) | ||
## v1.1.5 | ||
- make redis commit transactional | ||
#### v1.1.3 | ||
## v1.1.3 | ||
- if no passing a callback when initing a new repo, do not automatically connect | ||
#### v1.1.2 | ||
## v1.1.2 | ||
- replace json-serialize with jsondate | ||
#### v1.1.1 | ||
## v1.1.1 | ||
- added possibility for inmemory implementation to search with multiple values | ||
#### v1.1.0 | ||
## v1.1.0 | ||
- added possibility to pass query options | ||
#### v1.0.3 | ||
## v1.0.3 | ||
- parse json with json-serialize | ||
#### v1.0.2 | ||
## v1.0.2 | ||
- mongodb define index as string too | ||
#### v1.0.1 | ||
## v1.0.1 | ||
- added toJSON function on result array of find function | ||
#### v1.0.0 | ||
## v1.0.0 | ||
- IMPORTANT: changed API!!! | ||
- added redis support |
Sorry, the diff of this file is not supported yet
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
55937
1514