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 378fd96a
authored
Mar 03, 2013
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
store enums as text for sqlite + added test that checks if stored enum value is restored correctly
1 parent
3e1a2f89
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
4 deletions
lib/dao.js
lib/dialects/sqlite/query-generator.js
spec/dao-factory.spec.js
spec/sequelize.spec.js
lib/dao.js
View file @
378fd96
...
...
@@ -121,7 +121,7 @@ module.exports = (function() {
var
definition
=
this
.
daoFactory
.
rawAttributes
[
attrName
]
,
isEnum
=
(
definition
.
type
===
'ENUM'
)
,
hasValue
=
(
typeof
values
[
attrName
]
!==
'undefined'
)
,
valueOutOfScope
=
(
definition
.
values
.
indexOf
(
values
[
attrName
])
===
-
1
)
,
valueOutOfScope
=
(
(
definition
.
values
||
[])
.
indexOf
(
values
[
attrName
])
===
-
1
)
if
(
isEnum
&&
hasValue
&&
valueOutOfScope
)
{
throw
new
Error
(
'Value "'
+
values
[
attrName
]
+
'" for ENUM '
+
attrName
+
' is out of allowed scope. Allowed values: '
+
definition
.
values
.
join
(
', '
))
...
...
lib/dialects/sqlite/query-generator.js
View file @
378fd96
...
...
@@ -152,7 +152,11 @@ module.exports = (function() {
,
replacements
=
{
type
:
dataType
.
type
}
if
(
dataType
.
type
===
DataTypes
.
ENUM
)
{
replacements
.
type
=
"INTEGER"
replacements
.
type
=
"TEXT"
if
(
!
(
Array
.
isArray
(
dataType
.
values
)
&&
(
dataType
.
values
.
length
>
0
)))
{
throw
new
Error
(
'Values for ENUM haven\'t been defined.'
)
}
}
if
(
dataType
.
hasOwnProperty
(
'allowNull'
)
&&
!
dataType
.
allowNull
&&
!
dataType
.
primaryKey
)
{
...
...
spec/dao-factory.spec.js
View file @
378fd96
...
...
@@ -346,6 +346,28 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
done
()
})
})
describe
(
'enums'
,
function
()
{
before
(
function
(
done
)
{
this
.
Item
=
this
.
sequelize
.
define
(
'Item'
,
{
state
:
{
type
:
Helpers
.
Sequelize
.
ENUM
,
values
:
[
'available'
,
'in_cart'
,
'shipped'
]
}
})
this
.
sequelize
.
sync
({
force
:
true
}).
success
(
function
()
{
this
.
Item
.
create
({
state
:
'available'
}).
success
(
function
(
item
)
{
this
.
item
=
item
done
()
}.
bind
(
this
))
}.
bind
(
this
))
})
it
(
'correctly restores enum values'
,
function
(
done
)
{
this
.
Item
.
find
({
where
:
{
state
:
'available'
}}).
success
(
function
(
item
)
{
expect
(
item
.
id
).
toEqual
(
this
.
item
.
id
)
done
()
}.
bind
(
this
))
})
})
})
describe
(
'find'
,
function
find
()
{
...
...
spec/sequelize.spec.js
View file @
378fd96
...
...
@@ -143,7 +143,7 @@ describe(Helpers.getTestDialectTeaser("Sequelize"), function() {
this
.
Review
.
sync
({
force
:
true
}).
success
(
done
)
})
it
(
'
=>
raises an error if no values are defined'
,
function
()
{
it
(
'raises an error if no values are defined'
,
function
()
{
Helpers
.
assertException
(
function
()
{
this
.
sequelize
.
define
(
'omnomnom'
,
{
bla
:
{
type
:
Helpers
.
Sequelize
.
ENUM
}
...
...
@@ -167,7 +167,7 @@ describe(Helpers.getTestDialectTeaser("Sequelize"), function() {
}.
bind
(
this
))
})
it
(
"
=>
doesn't save an instance if value is not in the range of enums"
,
function
()
{
it
(
"doesn't save an instance if value is not in the range of enums"
,
function
()
{
Helpers
.
assertException
(
function
()
{
this
.
Review
.
create
({
status
:
'fnord'
})
}.
bind
(
this
),
'Value "fnord" for ENUM status is out of allowed scope. Allowed values: scheduled, active, finished'
)
...
...
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