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 ecd3de33
authored
Mar 23, 2013
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
enum can now be defined with Sequelize.ENUM('asd1', 'asd2', 'asd3')
1 parent
fa0167d9
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
33 additions
and
14 deletions
lib/dao.js
lib/data-types.js
lib/dialects/mysql/query-generator.js
lib/dialects/postgres/query-generator.js
lib/dialects/sqlite/query-generator.js
spec/sequelize.spec.js
lib/dao.js
View file @
ecd3de3
...
@@ -121,7 +121,7 @@ module.exports = (function() {
...
@@ -121,7 +121,7 @@ module.exports = (function() {
for
(
var
attrName
in
this
.
daoFactory
.
rawAttributes
)
{
for
(
var
attrName
in
this
.
daoFactory
.
rawAttributes
)
{
if
(
this
.
daoFactory
.
rawAttributes
.
hasOwnProperty
(
attrName
))
{
if
(
this
.
daoFactory
.
rawAttributes
.
hasOwnProperty
(
attrName
))
{
var
definition
=
this
.
daoFactory
.
rawAttributes
[
attrName
]
var
definition
=
this
.
daoFactory
.
rawAttributes
[
attrName
]
,
isEnum
=
(
definition
.
type
===
'ENUM'
)
,
isEnum
=
(
definition
.
type
&&
(
definition
.
type
.
toString
()
===
DataTypes
.
ENUM
.
toString
())
)
,
hasValue
=
(
typeof
values
[
attrName
]
!==
'undefined'
)
,
hasValue
=
(
typeof
values
[
attrName
]
!==
'undefined'
)
,
valueOutOfScope
=
((
definition
.
values
||
[]).
indexOf
(
values
[
attrName
])
===
-
1
)
,
valueOutOfScope
=
((
definition
.
values
||
[]).
indexOf
(
values
[
attrName
])
===
-
1
)
...
...
lib/data-types.js
View file @
ecd3de3
...
@@ -7,13 +7,30 @@ module.exports = {
...
@@ -7,13 +7,30 @@ module.exports = {
BOOLEAN
:
'TINYINT(1)'
,
BOOLEAN
:
'TINYINT(1)'
,
FLOAT
:
'FLOAT'
,
FLOAT
:
'FLOAT'
,
NOW
:
'NOW'
,
NOW
:
'NOW'
,
ENUM
:
'ENUM'
,
get
ENUM
()
{
var
result
=
function
()
{
return
{
type
:
'ENUM'
,
values
:
Array
.
prototype
.
slice
.
call
(
arguments
).
reduce
(
function
(
result
,
element
)
{
return
result
.
concat
(
Array
.
isArray
(
element
)
?
element
:
[
element
])
},
[])
}
}
result
.
toString
=
result
.
valueOf
=
function
()
{
return
'ENUM'
}
return
result
},
get
DECIMAL
()
{
get
DECIMAL
()
{
var
ret
=
function
(
precision
,
scale
)
{
var
result
=
function
(
precision
,
scale
)
{
return
'DECIMAL('
+
precision
+
','
+
scale
+
')'
;
return
'DECIMAL('
+
precision
+
','
+
scale
+
')'
};
}
ret
.
toString
=
ret
.
valueOf
=
function
()
{
return
'DECIMAL'
;
};
return
ret
;
result
.
toString
=
result
.
valueOf
=
function
()
{
return
'DECIMAL'
}
return
result
},
},
ARRAY
:
function
(
type
)
{
return
type
+
'[]'
}
ARRAY
:
function
(
type
)
{
return
type
+
'[]'
}
}
}
lib/dialects/mysql/query-generator.js
View file @
ecd3de3
...
@@ -378,7 +378,7 @@ module.exports = (function() {
...
@@ -378,7 +378,7 @@ module.exports = (function() {
var
template
=
"<%= type %>"
var
template
=
"<%= type %>"
,
replacements
=
{
type
:
dataType
.
type
}
,
replacements
=
{
type
:
dataType
.
type
}
if
(
dataType
.
type
===
DataTypes
.
ENUM
)
{
if
(
dataType
.
type
.
toString
()
===
DataTypes
.
ENUM
.
toString
()
)
{
if
(
Array
.
isArray
(
dataType
.
values
)
&&
(
dataType
.
values
.
length
>
0
))
{
if
(
Array
.
isArray
(
dataType
.
values
)
&&
(
dataType
.
values
.
length
>
0
))
{
replacements
.
type
=
"ENUM("
+
Utils
.
_
.
map
(
dataType
.
values
,
function
(
value
)
{
replacements
.
type
=
"ENUM("
+
Utils
.
_
.
map
(
dataType
.
values
,
function
(
value
)
{
return
Utils
.
escape
(
value
)
return
Utils
.
escape
(
value
)
...
...
lib/dialects/postgres/query-generator.js
View file @
ecd3de3
...
@@ -518,7 +518,7 @@ module.exports = (function() {
...
@@ -518,7 +518,7 @@ module.exports = (function() {
var
template
=
"<%= type %>"
var
template
=
"<%= type %>"
,
replacements
=
{
type
:
dataType
.
type
}
,
replacements
=
{
type
:
dataType
.
type
}
if
(
dataType
.
type
===
DataTypes
.
ENUM
)
{
if
(
dataType
.
type
.
toString
()
===
DataTypes
.
ENUM
.
toString
()
)
{
if
(
Array
.
isArray
(
dataType
.
values
)
&&
(
dataType
.
values
.
length
>
0
))
{
if
(
Array
.
isArray
(
dataType
.
values
)
&&
(
dataType
.
values
.
length
>
0
))
{
replacements
.
type
=
"ENUM("
+
Utils
.
_
.
map
(
dataType
.
values
,
function
(
value
)
{
replacements
.
type
=
"ENUM("
+
Utils
.
_
.
map
(
dataType
.
values
,
function
(
value
)
{
return
Utils
.
escape
(
value
)
return
Utils
.
escape
(
value
)
...
...
lib/dialects/sqlite/query-generator.js
View file @
ecd3de3
...
@@ -151,7 +151,7 @@ module.exports = (function() {
...
@@ -151,7 +151,7 @@ module.exports = (function() {
var
template
=
"<%= type %>"
var
template
=
"<%= type %>"
,
replacements
=
{
type
:
dataType
.
type
}
,
replacements
=
{
type
:
dataType
.
type
}
if
(
dataType
.
type
===
DataTypes
.
ENUM
)
{
if
(
dataType
.
type
.
toString
()
===
DataTypes
.
ENUM
.
toString
()
)
{
replacements
.
type
=
"TEXT"
replacements
.
type
=
"TEXT"
if
(
!
(
Array
.
isArray
(
dataType
.
values
)
&&
(
dataType
.
values
.
length
>
0
)))
{
if
(
!
(
Array
.
isArray
(
dataType
.
values
)
&&
(
dataType
.
values
.
length
>
0
)))
{
...
...
spec/sequelize.spec.js
View file @
ecd3de3
...
@@ -153,12 +153,13 @@ describe(Helpers.getTestDialectTeaser("Sequelize"), function() {
...
@@ -153,12 +153,13 @@ describe(Helpers.getTestDialectTeaser("Sequelize"), function() {
})
})
describe
(
'define'
,
function
()
{
describe
(
'define'
,
function
()
{
[
{
type
:
Helpers
.
Sequelize
.
ENUM
,
values
:
[
'scheduled'
,
'active'
,
'finished'
]},
Helpers
.
Sequelize
.
ENUM
(
'scheduled'
,
'active'
,
'finished'
)
].
forEach
(
function
(
status
)
{
describe
(
'enum'
,
function
()
{
describe
(
'enum'
,
function
()
{
before
(
function
(
done
)
{
before
(
function
(
done
)
{
this
.
Review
=
this
.
sequelize
.
define
(
'review'
,
{
this
.
Review
=
this
.
sequelize
.
define
(
'review'
,
{
status
:
status
})
status
:
{
type
:
Helpers
.
Sequelize
.
ENUM
,
values
:
[
'scheduled'
,
'active'
,
'finished'
]}
})
this
.
Review
.
sync
({
force
:
true
}).
success
(
done
)
this
.
Review
.
sync
({
force
:
true
}).
success
(
done
)
})
})
...
@@ -193,4 +194,5 @@ describe(Helpers.getTestDialectTeaser("Sequelize"), function() {
...
@@ -193,4 +194,5 @@ describe(Helpers.getTestDialectTeaser("Sequelize"), function() {
})
})
})
})
})
})
})
})
})
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