Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
public
/
sequelize
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
不要怂,就是干,撸起袖子干!
Commit a6c76249
authored
Mar 08, 2014
by
Jan Aagaard Meier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added CHAR datatype, closes #1209
1 parent
b68e5345
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
1 deletions
lib/data-types.js
test/data-types.test.js
lib/data-types.js
View file @
a6c7624
...
@@ -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
,
...
...
test/data-types.test.js
View file @
a6c7624
...
@@ -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'
],
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment