knex-model
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -17,14 +17,31 @@ 'use strict'; | ||
Base.find = function(query) { | ||
var self = this; | ||
var knex = this._knex(this._tableName); | ||
// default find all | ||
if(typeof query === 'undefined') { | ||
Array.prototype.push.call(arguments, {}); | ||
if(query) { | ||
knex = knex.where.apply(knex, arguments); | ||
} | ||
return knex.select().map(function(item) { | ||
return self.new(item); | ||
}); | ||
}; | ||
Base.first = function(query) { | ||
var self = this; | ||
var knex = this._knex(this._tableName); | ||
return knex.where.apply(knex, arguments).select().map(function(item) { | ||
return self.new(item); | ||
if(query) { | ||
knex = knex.where.apply(knex, arguments); | ||
} | ||
return knex.first().then(function(result) { | ||
return self.new(result); | ||
}); | ||
}; | ||
Base.where = function() { | ||
var knex = this._knex(this._tableName); | ||
return knex.where.apply(knex, arguments); | ||
}; | ||
Base.create = function(params) { | ||
@@ -31,0 +48,0 @@ return this._knex(this._tableName).insert(params); |
@@ -7,3 +7,3 @@ 'use strict'; | ||
var KenxModel = { | ||
VERSION: '0.0.2', | ||
VERSION: '0.0.3', | ||
define: define | ||
@@ -33,2 +33,4 @@ }; | ||
model._name = name; | ||
// save super class prototype | ||
@@ -42,3 +44,3 @@ model.prototype.super = Base.prototype; | ||
momery[name] = model; | ||
momery[model._name] = model; | ||
@@ -45,0 +47,0 @@ return model; |
{ | ||
"name": "knex-model", | ||
"version": "0.0.2", | ||
"description": "", | ||
"version": "0.0.3", | ||
"description": "Small ORM", | ||
"main": "index.js", | ||
@@ -14,2 +14,6 @@ "scripts": { | ||
}, | ||
"keywords": [ | ||
"knex", | ||
"model" | ||
], | ||
"author": "Chunpeng Wen", | ||
@@ -16,0 +20,0 @@ "license": "ISC", |
# knex-model | ||
...... | ||
Small ORM. | ||
It is built atop the [Knex Query Builder](http://knexjs.org/) | ||
@@ -5,0 +6,0 @@ ## Example |
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
6519
165
57