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 5bc9b5d9
authored
Oct 15, 2013
by
Sascha Depold
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into features/mariadb
2 parents
30991dd1
ba5918b2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
1 deletions
lib/dialects/sqlite/query-generator.js
test/sqlite/query-generator.test.js
lib/dialects/sqlite/query-generator.js
View file @
5bc9b5d
...
@@ -55,7 +55,7 @@ module.exports = (function() {
...
@@ -55,7 +55,7 @@ module.exports = (function() {
return
Utils
.
_
.
includes
(
definition
,
'PRIMARY KEY'
)
return
Utils
.
_
.
includes
(
definition
,
'PRIMARY KEY'
)
}).
length
>
1
)
}).
length
>
1
)
,
attrStr
=
[]
,
attrStr
=
[]
,
modifierLastIndex
=
-
1
for
(
var
attr
in
attributes
)
{
for
(
var
attr
in
attributes
)
{
if
(
attributes
.
hasOwnProperty
(
attr
))
{
if
(
attributes
.
hasOwnProperty
(
attr
))
{
...
@@ -65,6 +65,26 @@ module.exports = (function() {
...
@@ -65,6 +65,26 @@ module.exports = (function() {
dataType
=
dataType
.
replace
(
/BIGINT/
,
'INTEGER'
)
dataType
=
dataType
.
replace
(
/BIGINT/
,
'INTEGER'
)
}
}
// SQLite thinks that certain modifiers should come before the length declaration,
// whereas other dialects want them after, see http://www.sqlite.org/lang_createtable.html.
// Start by finding the index of the last of the modifiers
[
'UNSIGNED'
,
'BINARY'
,
'ZEROFILL'
].
forEach
(
function
(
modifier
)
{
var
tmpIndex
=
dataType
.
indexOf
(
modifier
)
if
(
tmpIndex
>
modifierLastIndex
)
{
modifierLastIndex
=
tmpIndex
+
modifier
.
length
}
})
if
(
modifierLastIndex
)
{
// If a modifier was found, and a lenght declaration is given before the modifier, move the length
var
length
=
dataType
.
match
(
/
\(\s
*
\d
+
(\s
*,
\s
*
\d)?\s
*
\)
/
)
if
(
length
&&
length
.
index
<
modifierLastIndex
)
{
dataType
=
dataType
.
replace
(
length
[
0
],
''
)
dataType
=
Utils
.
_
.
insert
(
dataType
,
modifierLastIndex
,
length
[
0
])
}
}
if
(
Utils
.
_
.
includes
(
dataType
,
'PRIMARY KEY'
)
&&
needsMultiplePrimaryKeys
)
{
if
(
Utils
.
_
.
includes
(
dataType
,
'PRIMARY KEY'
)
&&
needsMultiplePrimaryKeys
)
{
primaryKeys
.
push
(
attr
)
primaryKeys
.
push
(
attr
)
attrStr
.
push
(
this
.
quoteIdentifier
(
attr
)
+
" "
+
dataType
.
replace
(
/PRIMARY KEY/
,
'NOT NULL'
))
attrStr
.
push
(
this
.
quoteIdentifier
(
attr
)
+
" "
+
dataType
.
replace
(
/PRIMARY KEY/
,
'NOT NULL'
))
...
...
test/sqlite/query-generator.test.js
View file @
5bc9b5d
...
@@ -91,6 +91,10 @@ if (dialect === 'sqlite') {
...
@@ -91,6 +91,10 @@ if (dialect === 'sqlite') {
expectation
:
"CREATE TABLE IF NOT EXISTS `myTable` (`title` VARCHAR(255), `name` VARCHAR(255));"
expectation
:
"CREATE TABLE IF NOT EXISTS `myTable` (`title` VARCHAR(255), `name` VARCHAR(255));"
},
},
{
{
arguments
:
[
'myTable'
,
{
title
:
'VARCHAR(255) BINARY'
,
number
:
'INTEGER(5) UNSIGNED'
}],
expectation
:
"CREATE TABLE IF NOT EXISTS `myTable` (`title` VARCHAR BINARY(255), `number` INTEGER UNSIGNED(5));"
},
{
arguments
:
[
'myTable'
,
{
title
:
'ENUM("A", "B", "C")'
,
name
:
'VARCHAR(255)'
}],
arguments
:
[
'myTable'
,
{
title
:
'ENUM("A", "B", "C")'
,
name
:
'VARCHAR(255)'
}],
expectation
:
"CREATE TABLE IF NOT EXISTS `myTable` (`title` ENUM(\"A\", \"B\", \"C\"), `name` VARCHAR(255));"
expectation
:
"CREATE TABLE IF NOT EXISTS `myTable` (`title` ENUM(\"A\", \"B\", \"C\"), `name` VARCHAR(255));"
},
},
...
...
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