Comparing version 1.2.2 to 1.3.0
@@ -164,2 +164,29 @@ var util = require('util'); | ||
function patchInsert(table, data, keyProperties, cb) { | ||
var q = this.query.insert() | ||
.into(table) | ||
.set(data) | ||
.build(); | ||
this.db.all(q, function (err, info) { | ||
if (err) return cb(err); | ||
if (!keyProperties) return cb(null); | ||
var i, ids = {}, | ||
prop; | ||
if (keyProperties.length == 1 && keyProperties[0].type == 'serial') { | ||
ids[keyProperties[0].name] = info.insertId; | ||
return cb(null, ids); | ||
} else { | ||
for (i = 0; i < keyProperties.length; i++) { | ||
prop = keyProperties[i]; | ||
// Zero is a valid value for an ID column | ||
ids[prop.name] = data[prop.mapsTo] !== undefined ? data[prop.mapsTo] : null; | ||
} | ||
return cb(null, ids); | ||
} | ||
}.bind(this)); | ||
}; | ||
function execQuerySync(query, opt) { | ||
@@ -192,2 +219,5 @@ if (arguments.length == 2) | ||
if (db.driver.dialect === 'sqlite') | ||
db.driver.insert = patchInsert; | ||
var def = db.define; | ||
@@ -194,0 +224,0 @@ db.define = function (name, properties, opts) { |
{ | ||
"name": "fib-orm", | ||
"version": "1.2.2", | ||
"version": "1.3.0", | ||
"description": "Object Relational Mapping for fibjs", | ||
@@ -5,0 +5,0 @@ "main": "lib", |
33825
271
8