Socket
Socket
Sign inDemoInstall

viewmodel

Package Overview
Dependencies
Maintainers
2
Versions
109
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

viewmodel - npm Package Compare versions

Comparing version 1.2.8 to 1.3.0

lib/databases/documentdb.js

30

lib/base.js

@@ -69,3 +69,7 @@ 'use strict';

*/
find: function (query, callback) {
find: function (query, queryOptions, callback) {
if (!callback) {
callback = queryOptions;
queryOptions = {};
}
implementError(callback);

@@ -75,2 +79,26 @@ },

/**
* Use this function to find one viewmodel.
* @param {String} query The query to find the viewmodel. (mongodb style) [optional]
* @param {Function} callback The function, that will be called when the this action is completed.
* `function(err, vm){}` vm is of type Object.
*/
findOne: function (query, queryOptions, callback) {
if (!queryOptions) {
callback = query;
query = {};
queryOptions = {};
} else if (!callback) {
callback = queryOptions;
queryOptions = {};
}
this.find(query, queryOptions, function (err, items) {
if (err) {
return callback(err);
}
callback(null, items[0]);
});
},
/**
* Use this function to commit/save a viewmodel.

@@ -77,0 +105,0 @@ * @param {Object} vm The vm to commit.

@@ -153,2 +153,24 @@ 'use strict';

findOne: function(query, queryOptions, callback) {
this.checkConnection();
var self = this;
this.collection.findOne(query, queryOptions, function(err, data) {
if (err) {
return callback(err);
}
if (!data) {
return callback(null, null);
}
var vm = new ViewModel(data, self);
vm.actionOnCommit = 'update';
callback(null, vm);
});
},
commit: function(vm, callback) {

@@ -155,0 +177,0 @@

@@ -215,2 +215,36 @@ 'use strict';

findOne: function(query, queryOptions, callback) {
this.checkConnection();
var self = this;
this.client.keys(this.prefix + ':*', function(err, docs) {
self.client.get(docs[0], function (err, data) {
if (err) {
if (callback) callback(err);
return;
}
if (!data) {
if (callback) callback(null, null);
return;
}
var result;
try {
result = jsondate.parse(data.toString());
} catch (error) {
if (callback) callback(err);
return;
}
var vm = new ViewModel(result, self);
vm.actionOnCommit = 'update';
if (callback) callback(null, vm);
});
});
},
commit: function (vm, callback) {

@@ -217,0 +251,0 @@

@@ -111,2 +111,24 @@ 'use strict';

findOne: function(query, queryOptions, callback) {
this.checkConnection();
var self = this;
this.collection.findOne(query, queryOptions, function(err, data) {
if (err) {
return callback(err);
}
if (!data) {
return callback(null, null);
}
var vm = new ViewModel(data, self);
vm.actionOnCommit = 'update';
callback(null, vm);
});
},
commit: function(vm, callback) {

@@ -113,0 +135,0 @@

@@ -80,2 +80,3 @@ 'use strict';

function removeWriteStuffFromVm (vm) {
if (!vm) { return; }
vm.destroy = permissionError;

@@ -145,2 +146,15 @@ vm.set = function() {

};
var orgFindOne = repo.findOne;
repo.findOne = function (query, queryOptions, callback) {
if (typeof query === 'function') {
callback = query;
query = {};
queryOptions = {};
}
if (typeof queryOptions === 'function') {
callback = queryOptions;
queryOptions = {};
}
orgFindOne.apply(this, [query, queryOptions, callback]);
};
// Do not modify anything... it's write and we can do everything!!!

@@ -225,3 +239,24 @@ connect(repo, options, callback);

};
var orgFindOne = repo.findOne;
repo.findOne = function (query, queryOptions, callback) {
if (typeof query === 'function') {
callback = query;
query = {};
queryOptions = {};
}
if (typeof queryOptions === 'function') {
callback = queryOptions;
queryOptions = {};
}
orgFindOne.apply(this, [query, queryOptions, function (err, res) {
if (err) {
return callback(err);
}
removeWriteStuffFromVm(res);
callback(null, res);
}]);
};
connect(repo, options, callback);

@@ -228,0 +263,0 @@ return repo;

10

package.json
{
"author": "adrai",
"name": "viewmodel",
"version": "1.2.8",
"version": "1.3.0",
"private": false,

@@ -23,9 +23,11 @@ "main": "index.js",

"devDependencies": {
"azure-storage": ">=0.3.0",
"cradle": ">=0.6.7",
"documentdb": ">=0.9.3",
"doqmentdb": ">=0.2.7",
"expect.js": ">= 0.1.2",
"mocha": ">= 1.0.1",
"mongodb": ">= 0.0.1",
"tingodb": ">= 0.0.1",
"redis": ">= 0.10.1",
"azure-storage": ">=0.3.0"
"tingodb": ">= 0.0.1"
},

@@ -71,4 +73,4 @@ "description": "Node-viewmodel is a node.js module for multiple databases. It can be very useful if you work with (d)ddd, cqrs, eventdenormalizer, host, etc.",

"scripts": {
"test": "mocha test/repositoryTest.js && mocha test/viewmodelTest.js && mocha test/repositoryWriteTest.js && mocha test/repositoryReadTest.js"
"test": "mocha"
}
}

@@ -115,2 +115,17 @@ # Introduction

## FindOne
// the query object ist like in mongoDb...
dummyRepo.findOne({ color: 'green' }, function(err, vm) {
if(err) {
console.log('ohhh :-(');
return;
}
console.log('the id: ' + vm.id);
if (vm.has('color')) {
console.log('the saved value: ' + vm.get('color'));
}
});
## Find by id...

@@ -198,2 +213,3 @@

6. azuretable ([azure-storage](https://github.com/Azure/azure-storage-node))
7. documentdb ([documentdb](https://github.com/Azure/azure-documentdb-node), [doqmentdb](https://github.com/a8m/doqmentdb))

@@ -200,0 +216,0 @@ ## own db implementation

@@ -0,1 +1,5 @@

## [v1.3.0](https://github.com/adrai/node-viewmodel/compare/v1.2.8...v1.3.0)
- added documentdb support [#11](https://github.com/adrai/node-viewmodel/pull/11) thanks to [sbiaudet](https://github.com/sbiaudet)
- added findOne functionality
## [v1.2.8](https://github.com/adrai/node-viewmodel/compare/v1.2.7...v1.2.8)

@@ -2,0 +6,0 @@ - some fix for azure-table [#9](https://github.com/adrai/node-viewmodel/pull/9) thanks to [sbiaudet](https://github.com/sbiaudet)

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc