Skip to content

Commit

Permalink
add SQLite boolean mapping (should close sequelize#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexstrat committed Apr 4, 2012
1 parent 66cc025 commit 358c9c0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/dao-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
19 changes: 19 additions & 0 deletions lib/dialects/sqlite/query-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 || {}

Expand Down

0 comments on commit 358c9c0

Please sign in to comment.