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

Commit 9474edb4 by Sascha Depold

added Sequelize.BOOLEAN

1 parent 3fb4bb81
......@@ -35,6 +35,14 @@ To define mappings between a class (_Stop telling me that JavaScript don't know
deadline: Sequelize.DATE
})
Sequelize currently supports the following datatypes:
Sequelize.STRING ===> VARCHAR(255)
Sequelize.TEXT ===> TEXT
Sequelize.INTEGER ===> INT
Sequelize.DATE ===> DATETIME
Sequelize.BOOLEAN ===> TINYINT(1)
## Creation and deletion of class tables ##
As you are able to specify an objects _skeleton_, the next step is to push it to a database:
......
......@@ -16,6 +16,7 @@ var classMethods = {
TEXT: 'TEXT',
INTEGER: 'INT',
DATE: 'DATETIME',
BOOLEAN: 'TINYINT(1) NOT NULL',
sqlQueryFor: function(command, values) {
var query = null
......
......@@ -60,6 +60,9 @@ SequelizeHelper = {
if((value == null)||(typeof value == 'undefined'))
return "NULL"
if(dataType.indexOf(Sequelize.BOOLEAN) > -1)
return (value === true ? 1 : 0)
if(dataType.indexOf(Sequelize.INTEGER) > -1)
return value
......
......@@ -9,8 +9,12 @@ SequelizeTable = function(sequelize, tableName, attributes) {
var table = function(values) {
var self = this
SequelizeHelper.Hash.forEach(values, function(value, key) {
if(attributes[key])
if(attributes[key]) {
if(attributes[key] == Sequelize.BOOLEAN) {
self[key] = ((value == 1) || (value == true)) ? true : false
} else
self[key] = value
}
})
this.id = null // specify id as null to declare this object as unsaved and as not present in the database
this.table = table
......@@ -301,7 +305,7 @@ SequelizeTable = function(sequelize, tableName, attributes) {
var self = this
SequelizeHelper.Hash.keys(table.attributes).forEach(function(attribute) {
result[attribute] = self[attribute] || null
result[attribute] = (typeof self[attribute] == "undefined") ? null : self[attribute]
})
return result
......@@ -331,7 +335,7 @@ SequelizeTable = function(sequelize, tableName, attributes) {
updateAttributes: function(newValues, callback) {
var self = this
SequelizeHelper.Hash.keys(table.attributes).forEach(function(attribute) {
if(newValues[attribute])
if(typeof newValues[attribute] != 'undefined')
self[attribute] = newValues[attribute]
})
this.save(callback)
......
......@@ -301,5 +301,19 @@ module.exports = {
assert.equal(true, IsAssociatedWithTestOne.isAssociatedWith(IsAssociatedWithTestTwo, 'belongsTo'))
assert.equal(false, IsAssociatedWithTestOne.isAssociatedWith(IsAssociatedWithTestTwo, 'hasMany'))
assert.equal(false, IsAssociatedWithTestOne.isAssociatedWith(IsAssociatedWithTestTwo, 'hasOne'))
},
'boolean ==> save': function(assert, beforeExit) {
var BooleanTest = s.define("BooleanTest", {flag: Sequelize.BOOLEAN})
var testIsFinished = false
BooleanTest.sync(function() {
new BooleanTest({flag: true}).save(function(obj) {
assert.equal(obj.flag, true)
obj.updateAttributes({flag: false}, function(obj2) {
assert.equal(obj2.flag, false)
testIsFinished = true
})
})
})
beforeExit(function() { assert.equal(true, testIsFinished) })
}
}
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!