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 884a93ed
authored
Feb 05, 2013
by
Kevin Martin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added ENUM type
1 parent
602b1436
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
1 deletions
lib/data-types.js
lib/dialects/mysql/query-generator.js
lib/dialects/postgres/query-generator.js
lib/dialects/sqlite/query-generator.js
lib/data-types.js
View file @
884a93e
...
...
@@ -6,5 +6,6 @@ module.exports = {
DATE
:
'DATETIME'
,
BOOLEAN
:
'TINYINT(1)'
,
FLOAT
:
'FLOAT'
,
NOW
:
'NOW'
NOW
:
'NOW'
,
ENUM
:
'ENUM'
}
lib/dialects/mysql/query-generator.js
View file @
884a93e
...
...
@@ -381,6 +381,12 @@ module.exports = (function() {
var
template
=
"<%= type %>"
,
replacements
=
{
type
:
dataType
.
type
}
if
(
dataType
.
type
===
DataTypes
.
ENUM
&&
Array
.
isArray
(
dataType
.
values
)
&&
dataType
.
values
.
length
>
0
)
{
replacements
.
type
=
"ENUM("
+
Utils
.
_
.
map
(
dataType
.
values
,
function
(
value
)
{
return
Utils
.
escape
(
value
)
}).
join
(
", "
)
+
")"
}
if
(
dataType
.
hasOwnProperty
(
'allowNull'
)
&&
(
!
dataType
.
allowNull
))
{
template
+=
" NOT NULL"
}
...
...
lib/dialects/postgres/query-generator.js
View file @
884a93e
...
...
@@ -84,6 +84,10 @@ module.exports = (function() {
for
(
var
attr
in
attributes
)
{
var
dataType
=
pgDataTypeMapping
(
tableName
,
attr
,
attributes
[
attr
])
attrStr
.
push
(
addQuotes
(
attr
)
+
" "
+
dataType
)
if
(
attributes
[
attr
].
type
.
match
(
/^ENUM
\(
/
))
{
query
=
"CREATE TYPE "
+
Utils
.
escape
(
"enum_"
+
tableName
+
"_"
+
attr
)
+
" AS "
+
attributes
[
attr
].
type
"; "
+
query
}
}
var
values
=
{
...
...
@@ -130,6 +134,10 @@ module.exports = (function() {
attrName
:
addQuotes
(
attrName
),
definition
:
pgDataTypeMapping
(
tableName
,
attrName
,
definition
)
}))
if
(
definition
.
type
.
match
(
/^ENUM
\(
/
))
{
query
=
"CREATE TYPE "
+
Utils
.
escape
(
"enum_"
+
tableName
+
"_"
+
attrName
)
+
" AS "
+
definition
.
type
"; "
+
query
}
}
return
Utils
.
_
.
template
(
query
)({
tableName
:
addQuotes
(
tableName
),
attributes
:
attrString
.
join
(
', '
)
})
...
...
@@ -167,6 +175,10 @@ module.exports = (function() {
})
sql
.
push
(
attrSql
)
if
(
definition
.
type
.
match
(
/^ENUM
\(
/
))
{
query
=
"CREATE TYPE "
+
Utils
.
escape
(
"enum_"
+
tableName
+
"_"
+
attributeName
)
+
" AS "
+
definition
.
type
"; "
+
query
}
}
return
sql
.
join
(
''
)
...
...
@@ -181,6 +193,10 @@ module.exports = (function() {
before
:
addQuotes
(
attrBefore
),
after
:
addQuotes
(
attributeName
),
}))
if
(
attributes
[
attributeName
].
type
.
match
(
/^ENUM
\(
/
))
{
query
=
"CREATE TYPE "
+
Utils
.
escape
(
"enum_"
+
tableName
+
"_"
+
attributeName
)
+
" AS "
+
attributes
[
attributeName
].
type
"; "
+
query
}
}
return
Utils
.
_
.
template
(
query
)({
tableName
:
addQuotes
(
tableName
),
attributes
:
attrString
.
join
(
', '
)
})
...
...
@@ -476,6 +492,12 @@ module.exports = (function() {
var
template
=
"<%= type %>"
,
replacements
=
{
type
:
dataType
.
type
}
if
(
dataType
.
type
===
DataTypes
.
ENUM
&&
Array
.
isArray
(
dataType
.
values
)
&&
dataType
.
values
.
length
>
0
)
{
replacements
.
type
=
"ENUM("
+
Utils
.
_
.
map
(
dataType
.
values
,
function
(
value
)
{
return
Utils
.
escape
(
value
)
}).
join
(
", "
)
+
")"
}
if
(
dataType
.
type
===
"TINYINT(1)"
)
{
dataType
.
type
=
'BOOLEAN'
}
...
...
lib/dialects/sqlite/query-generator.js
View file @
884a93e
...
...
@@ -123,6 +123,10 @@ module.exports = (function() {
var
template
=
"<%= type %>"
,
replacements
=
{
type
:
dataType
.
type
}
if
(
dataType
.
type
===
DataTypes
.
ENUM
)
{
replacements
.
type
=
"INTEGER"
}
if
(
dataType
.
hasOwnProperty
(
'allowNull'
)
&&
!
dataType
.
allowNull
&&
!
dataType
.
primaryKey
)
{
template
+=
" NOT NULL"
}
...
...
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