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

Commit 0d639ca8 by Sascha Depold

fixed boolean to tinyint conversion for sqlite

1 parent 6dab07a8
...@@ -149,7 +149,7 @@ module.exports = (function() { ...@@ -149,7 +149,7 @@ module.exports = (function() {
} }
if(options.where) { if(options.where) {
options.where = QueryGenerator.getWhereConditions(options.where, tableName) options.where = this.getWhereConditions(options.where, tableName)
query += " WHERE <%= where %>" query += " WHERE <%= where %>"
} }
...@@ -290,10 +290,10 @@ module.exports = (function() { ...@@ -290,10 +290,10 @@ module.exports = (function() {
if(Utils.isHash(smth)) { if(Utils.isHash(smth)) {
smth = Utils.prependTableNameToHash(tableName, smth) smth = Utils.prependTableNameToHash(tableName, smth)
result = QueryGenerator.hashToWhereConditions(smth) result = this.hashToWhereConditions(smth)
} else if (typeof smth === 'number') { } else if (typeof smth === 'number') {
smth = Utils.prependTableNameToHash(tableName, { id: smth }) smth = Utils.prependTableNameToHash(tableName, { id: smth })
result = QueryGenerator.hashToWhereConditions(smth) result = this.hashToWhereConditions(smth)
} else if (typeof smth === "string") { } else if (typeof smth === "string") {
result = smth result = smth
} else if (Array.isArray(smth)) { } else if (Array.isArray(smth)) {
......
var Utils = require("../../utils") var Utils = require("../../utils")
, util = require("util") var MySqlQueryGenerator = Utils._.extend(
Utils._.clone(require("../query-generator")),
Utils._.clone(require("../mysql/query-generator"))
)
var hashToWhereConditions = MySqlQueryGenerator.hashToWhereConditions
var escape = function(str) { var escape = function(str) {
if (typeof str === 'string') { if (typeof str === 'string') {
...@@ -24,12 +29,14 @@ module.exports = (function() { ...@@ -24,12 +29,14 @@ module.exports = (function() {
, attrStr = [] , attrStr = []
for (var attr in attributes) { for (var attr in attributes) {
var dataType = attributes[attr] if (attributes.hasOwnProperty(attr)) {
var dataType = attributes[attr]
if (Utils._.includes(dataType, 'PRIMARY KEY')) { if (Utils._.includes(dataType, 'PRIMARY KEY')) {
attrStr.push(Utils.addTicks(attr) + " " + dataType) attrStr.push(Utils.addTicks(attr) + " " + dataType)
} else { } else {
attrStr.push(Utils.addTicks(attr) + " " + dataType) attrStr.push(Utils.addTicks(attr) + " " + dataType)
}
} }
} }
...@@ -129,21 +136,34 @@ module.exports = (function() { ...@@ -129,21 +136,34 @@ module.exports = (function() {
var fields = [] var fields = []
for (var name in factory.attributes) { for (var name in factory.attributes) {
var definition = factory.attributes[name] if (factory.attributes.hasOwnProperty(name)) {
var definition = factory.attributes[name]
if (definition && (definition.indexOf('INTEGER PRIMARY KEY') == 0)) { if (definition && (definition.indexOf('INTEGER PRIMARY KEY') === 0)) {
fields.push(name) fields.push(name)
}
} }
} }
return fields return fields
},
hashToWhereConditions: function(hash) {
for (var key in hash) {
if (hash.hasOwnProperty(key)) {
var value = hash[key]
if (typeof value === 'boolean') {
value = !!value ? 1 : 0
}
hash[key] = value
}
}
return hashToWhereConditions(hash)
} }
} }
var MySqlQueryGenerator = Utils._.extend(
Utils._.clone(require("../query-generator")),
Utils._.clone(require("../mysql/query-generator"))
)
return Utils._.extend(MySqlQueryGenerator, QueryGenerator) return Utils._.extend(MySqlQueryGenerator, QueryGenerator)
})() })()
...@@ -215,9 +215,9 @@ dialects.forEach(function(dialect) { ...@@ -215,9 +215,9 @@ dialects.forEach(function(dialect) {
}) })
}) })
it("only get objects that fullfil the options", function(done) { it("only get objects that fulfill the options", function(done) {
this.User.find({where: {username: 'John'}}).success(function (john) { this.User.find({ where: { username: 'John' } }).success(function (john) {
john.getTasks({where: {active: true}, limit: 10, order: 'ID DESC'}).success(function (tasks) { john.getTasks({ where: { active: true }, limit: 10, order: 'id DESC' }).success(function (tasks) {
expect(tasks.length).toEqual(1) expect(tasks.length).toEqual(1)
done(); done();
}) })
...@@ -259,7 +259,7 @@ dialects.forEach(function(dialect) { ...@@ -259,7 +259,7 @@ dialects.forEach(function(dialect) {
}) })
}) })
it("only get objects that fullfil the options", function(done) { it("only get objects that fulfill the options", function(done) {
this.User.find({where: {username: 'John'}}).success(function (john) { this.User.find({where: {username: 'John'}}).success(function (john) {
john.getTasks({where: {active: true}}).success(function (tasks) { john.getTasks({where: {active: true}}).success(function (tasks) {
expect(tasks.length).toEqual(1) expect(tasks.length).toEqual(1)
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!