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

Commit 7032288e by Mick Hansen

Merge branch 'master' of github.com:sequelize/sequelize

2 parents d3b0388e a6c76249
Showing with 42 additions and 1 deletions
...@@ -11,6 +11,19 @@ var STRING = function(length, binary) { ...@@ -11,6 +11,19 @@ var STRING = function(length, binary) {
} }
} }
var CHAR = function (length, binary) {
if (this instanceof CHAR) {
this._binary = !!binary
if (typeof length === 'number') {
this._length = length
} else {
this._length = 255
}
} else {
return new CHAR(length, binary)
}
}
STRING.prototype = { STRING.prototype = {
get BINARY() { get BINARY() {
this._binary = true this._binary = true
...@@ -24,12 +37,31 @@ STRING.prototype = { ...@@ -24,12 +37,31 @@ STRING.prototype = {
} }
} }
CHAR.prototype = {
get BINARY() {
this._binary = true
return this
},
get type() {
return this.toString()
},
toString: function() {
return 'CHAR(' + this._length + ')' + ((this._binary) ? ' BINARY' : '')
}
}
Object.defineProperty(STRING, 'BINARY', { Object.defineProperty(STRING, 'BINARY', {
get: function() { get: function() {
return new STRING(undefined, true) return new STRING(undefined, true)
} }
}) })
Object.defineProperty(CHAR, 'BINARY', {
get: function() {
return new CHAR(undefined, true)
}
})
var INTEGER = function() { var INTEGER = function() {
return INTEGER.prototype.construct.apply(this, [INTEGER].concat(Array.prototype.slice.apply(arguments))) return INTEGER.prototype.construct.apply(this, [INTEGER].concat(Array.prototype.slice.apply(arguments)))
} }
...@@ -58,13 +90,15 @@ BIGINT._type = BIGINT ...@@ -58,13 +90,15 @@ BIGINT._type = BIGINT
BIGINT._typeName = 'BIGINT' BIGINT._typeName = 'BIGINT'
STRING._type = STRING STRING._type = STRING
STRING._typeName = 'VARCHAR' STRING._typeName = 'VARCHAR'
CHAR._type = CHAR
CHAR._typeName = 'CHAR'
BLOB._type = BLOB BLOB._type = BLOB
BLOB._typeName = 'BLOB' BLOB._typeName = 'BLOB'
DECIMAL._type = DECIMAL DECIMAL._type = DECIMAL
DECIMAL._typeName = 'DECIMAL' DECIMAL._typeName = 'DECIMAL'
BLOB.toString = STRING.toString = INTEGER.toString = FLOAT.toString = BIGINT.toString = DECIMAL.toString = function() { BLOB.toString = STRING.toString = CHAR.toString = INTEGER.toString = FLOAT.toString = BIGINT.toString = DECIMAL.toString = function() {
return new this._type().toString() return new this._type().toString()
} }
...@@ -218,6 +252,7 @@ var decimalDesc = { ...@@ -218,6 +252,7 @@ var decimalDesc = {
} }
Object.defineProperty(STRING, 'type', typeDesc) Object.defineProperty(STRING, 'type', typeDesc)
Object.defineProperty(CHAR, 'type', typeDesc)
Object.defineProperty(INTEGER, 'type', typeDesc) Object.defineProperty(INTEGER, 'type', typeDesc)
Object.defineProperty(BIGINT, 'type', typeDesc) Object.defineProperty(BIGINT, 'type', typeDesc)
Object.defineProperty(FLOAT, 'type', typeDesc) Object.defineProperty(FLOAT, 'type', typeDesc)
...@@ -237,6 +272,7 @@ Object.defineProperty(DECIMAL, 'SCALE', decimalDesc) ...@@ -237,6 +272,7 @@ Object.defineProperty(DECIMAL, 'SCALE', decimalDesc)
module.exports = { module.exports = {
STRING: STRING, STRING: STRING,
CHAR: CHAR,
TEXT: 'TEXT', TEXT: 'TEXT',
INTEGER: INTEGER, INTEGER: INTEGER,
......
...@@ -52,6 +52,11 @@ describe(Support.getTestDialectTeaser('DataTypes'), function() { ...@@ -52,6 +52,11 @@ describe(Support.getTestDialectTeaser('DataTypes'), function() {
[Sequelize.STRING(1234).BINARY, 'STRING(1234).BINARY', 'VARCHAR(1234) BINARY'], [Sequelize.STRING(1234).BINARY, 'STRING(1234).BINARY', 'VARCHAR(1234) BINARY'],
[Sequelize.STRING.BINARY, 'STRING.BINARY', 'VARCHAR(255) BINARY'], [Sequelize.STRING.BINARY, 'STRING.BINARY', 'VARCHAR(255) BINARY'],
[Sequelize.CHAR, 'CHAR(255)', 'CHAR(255)'],
[Sequelize.CHAR(12), 'CHAR(12)', 'CHAR(12)'],
[Sequelize.CHAR(12).BINARY, 'CHAR(12).BINARY', 'CHAR(12) BINARY'],
[Sequelize.CHAR.BINARY, 'CHAR(255).BINARY', 'CHAR(255) BINARY'],
[Sequelize.TEXT, 'TEXT', 'TEXT'], [Sequelize.TEXT, 'TEXT', 'TEXT'],
[Sequelize.DATE, 'DATE', 'DATETIME'], [Sequelize.DATE, 'DATE', 'DATETIME'],
[Sequelize.NOW, 'NOW', 'NOW'], [Sequelize.NOW, 'NOW', 'NOW'],
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!