waterline
Advanced tools
Comparing version 0.5.0 to 0.5.1
@@ -169,4 +169,5 @@ var async = require('async'); | ||
if (!_.isObject(model)) return; | ||
if (!model.save) model.save = _.bind(self.__save, self, collectionName, model); | ||
if (!model.destroy) model.destroy = _.bind(self.__destroy, self, collectionName, model); | ||
model.save = _.bind(self.__save, self, collectionName, model); | ||
model.destroy = _.bind(self.__destroy, self, collectionName, model); | ||
model.values = _.omit(model,['save','destroy','values']); | ||
}); | ||
@@ -178,4 +179,5 @@ return cb(err,set); | ||
// Add save() method to model | ||
if (!set.save) set.save = _.bind(self.__save, self, collectionName, set); | ||
if (!set.destroy) set.destroy = _.bind(self.__destroy, self, collectionName, set); | ||
set.save = _.bind(self.__save, self, collectionName, set); | ||
set.destroy = _.bind(self.__destroy, self, collectionName, set); | ||
set.values = _.omit(set,['save','destroy','values']); | ||
return cb(err,set); | ||
@@ -235,2 +237,14 @@ } | ||
this.update = function(collectionName, criteria, values, cb) { | ||
if (!criteria) return cb('No criteria or id specified!'); | ||
this.updateAll(collectionName, criteria, values, function (err, models) { | ||
if (!models) return cb(err); | ||
if (models.length < 1) return cb(err); | ||
else if (models.length > 1) return cb("More than one "+collectionName+" returned!"); | ||
else return cb(null,models[0]); | ||
}); | ||
}; | ||
this.updateAll = function (collectionName, criteria, values, cb) { | ||
// Build enhanced callback fn | ||
@@ -241,4 +255,3 @@ cb = this.decorateModel(collectionName, cb); | ||
criteria = normalize.criteria(criteria); | ||
adapterDef.update(collectionName, criteria, values, cb); | ||
return adapterDef.update(collectionName, criteria, values, cb); | ||
}; | ||
@@ -245,0 +258,0 @@ |
@@ -43,10 +43,2 @@ var _ = require('underscore'); | ||
// If any item in criteria is a parsable finite number, | ||
// search for both the INTEGER and STRING versions | ||
for(var attrName in criteria.where) { | ||
if(Math.pow(+criteria.where[attrName], 2) > 0) { | ||
criteria.where[attrName] = [+criteria.where[attrName], criteria.where[attrName]]; | ||
} | ||
} | ||
// If WHERE is {}, always change it back to null | ||
@@ -53,0 +45,0 @@ if(criteria.where && _.keys(criteria.where).length === 0) { |
{ | ||
"name": "waterline", | ||
"version": "0.5.0", | ||
"description": "Adaptable data access layer for Node.js", | ||
"version": "0.5.1", | ||
"description": "Active Record for Node.js", | ||
"main": "waterline.js", | ||
@@ -17,2 +17,4 @@ "directories": { | ||
"keywords": [ | ||
"active record", | ||
"activerecord", | ||
"orm", | ||
@@ -22,8 +24,6 @@ "mysql", | ||
"mongodb", | ||
"neo4j", | ||
"postgres", | ||
"sqlite", | ||
"adapter", | ||
"waterline", | ||
"sails" | ||
"sails", | ||
"rails" | ||
], | ||
@@ -30,0 +30,0 @@ "author": "Mike McNeil", |
@@ -185,5 +185,5 @@ // Dependencies | ||
process.on('SIGTERM', serverOnHalt); | ||
// If SIGINT or SIGTERM wasn't run, this is a dirty exit-- | ||
process.on('exit', function process_exit() { | ||
if (!exiting) log.warn("Server stopped itself."); | ||
// If SIGINT or SIGTERM wasn't run, this is a dirty exit-- | ||
if (!exiting) log.verbose('Server stopped.'); | ||
}); | ||
@@ -190,0 +190,0 @@ function serverOnHalt (){ |
126455
3194