不要怂,就是干,撸起袖子干!

Commit b933c8bd by Laurent Zuijdwijk

added min and max functions to the model

1 parent c740ae1a
...@@ -107,6 +107,26 @@ ModelDefinition.prototype.count = function(options) { ...@@ -107,6 +107,26 @@ ModelDefinition.prototype.count = function(options) {
return emitter.run() return emitter.run()
} }
ModelDefinition.prototype.max = function(field, options) {
var self = this
var emitter = new Utils.CustomEventEmitter(function() {
self.query(QueryGenerator.maxQuery(self.tableName, field,options), self, {plain: true}).on('success', function(obj) {
emitter.emit('success', obj['max'])
})
})
return emitter.run()
}
ModelDefinition.prototype.min = function(field, options) {
var self = this
var emitter = new Utils.CustomEventEmitter(function() {
self.query(QueryGenerator.minQuery(self.tableName, field,options), self, {plain: true}).on('success', function(obj) {
emitter.emit('success', obj['min'])
})
})
return emitter.run()
}
ModelDefinition.prototype.findAll = function(options) { ModelDefinition.prototype.findAll = function(options) {
return this.query(QueryGenerator.selectQuery(this.tableName, options)) return this.query(QueryGenerator.selectQuery(this.tableName, options))
} }
......
...@@ -78,7 +78,12 @@ var QueryGenerator = module.exports = { ...@@ -78,7 +78,12 @@ var QueryGenerator = module.exports = {
countQuery: function(tableName, options) { countQuery: function(tableName, options) {
return QueryGenerator.selectQuery(tableName, options).replace("*", "count(*)") return QueryGenerator.selectQuery(tableName, options).replace("*", "count(*)")
}, },
maxQuery: function(tableName, field,options) {
return QueryGenerator.selectQuery(tableName ,options).replace("*", "max("+field+") as max")
},
minQuery: function(tableName, field,options) {
return QueryGenerator.selectQuery(tableName ,options).replace("*", "min("+field+") as min")
},
/* /*
Returns an insert into command. Parameters: table name + hash of attribute-value-pairs. Returns an insert into command. Parameters: table name + hash of attribute-value-pairs.
*/ */
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!