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

Commit 358c9c08 by Lachèze Alexandre

add SQLite boolean mapping (should close #149)

1 parent 66cc025c
......@@ -154,6 +154,10 @@ module.exports = (function() {
instance.__factory = this
Utils._.map(this.attributes, function(definition, name) {
if(definition.indexOf(DataTypes.BOOLEAN) !== -1 && typeof instance[name] === "number") {
instance[name] = (instance[name] === 0) ? false : true;
}
if(typeof instance[name] == 'undefined') {
var value = null
......
......@@ -29,6 +29,25 @@ module.exports = (function() {
return "SELECT name FROM sqlite_master WHERE type='table';"
},
insertQuery: function(tableName, attrValueHash) {
var query = "INSERT INTO <%= table %> (<%= attributes %>) VALUES (<%= values %>);";
var replacements = {
table: Utils.addTicks(tableName),
attributes: Utils._.keys(attrValueHash).map(function(attr){return Utils.addTicks(attr)}).join(","),
values: Utils._.values(attrValueHash).map(function(value){
//SQLite has no type boolean :
if(typeof value == "boolean")
value = value ? 1:0;
return Utils.escape((value instanceof Date) ? Utils.toSqlDate(value) : value)
}).join(",")
}
return Utils._.template(query)(replacements)
},
deleteQuery: function(tableName, where, options) {
options = options || {}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!