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 a6bc9064
authored
Oct 14, 2012
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed multiple primary keys in sqlite => many-to-many associations are now correctly working *meep*
1 parent
e5c824db
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
8 deletions
lib/dialects/sqlite/query-generator.js
lib/dialects/sqlite/query-generator.js
View file @
a6bc906
...
@@ -25,15 +25,21 @@ module.exports = (function() {
...
@@ -25,15 +25,21 @@ module.exports = (function() {
createTableQuery
:
function
(
tableName
,
attributes
,
options
)
{
createTableQuery
:
function
(
tableName
,
attributes
,
options
)
{
options
=
options
||
{}
options
=
options
||
{}
var
query
=
"CREATE TABLE IF NOT EXISTS <%= table %> (<%= attributes%>)"
var
query
=
"CREATE TABLE IF NOT EXISTS <%= table %> (<%= attributes%>)"
,
attrStr
=
[]
,
primaryKeys
=
[]
,
needsMultiplePrimaryKeys
=
(
Utils
.
_
.
values
(
attributes
).
filter
(
function
(
definition
)
{
return
Utils
.
_
.
includes
(
definition
,
'PRIMARY KEY'
)
}).
length
>
1
)
,
attrStr
=
[]
for
(
var
attr
in
attributes
)
{
for
(
var
attr
in
attributes
)
{
if
(
attributes
.
hasOwnProperty
(
attr
))
{
if
(
attributes
.
hasOwnProperty
(
attr
))
{
var
dataType
=
attributes
[
attr
]
var
dataType
=
attributes
[
attr
]
if
(
Utils
.
_
.
includes
(
dataType
,
'PRIMARY KEY'
))
{
if
(
Utils
.
_
.
includes
(
dataType
,
'PRIMARY KEY'
)
&&
needsMultiplePrimaryKeys
)
{
attrStr
.
push
(
Utils
.
addTicks
(
attr
)
+
" "
+
dataType
)
primaryKeys
.
push
(
attr
)
attrStr
.
push
(
Utils
.
addTicks
(
attr
)
+
" "
+
dataType
.
replace
(
/PRIMARY KEY/
,
'NOT NULL'
))
}
else
{
}
else
{
attrStr
.
push
(
Utils
.
addTicks
(
attr
)
+
" "
+
dataType
)
attrStr
.
push
(
Utils
.
addTicks
(
attr
)
+
" "
+
dataType
)
}
}
...
@@ -45,6 +51,11 @@ module.exports = (function() {
...
@@ -45,6 +51,11 @@ module.exports = (function() {
attributes
:
attrStr
.
join
(
", "
),
attributes
:
attrStr
.
join
(
", "
),
charset
:
(
options
.
charset
?
"DEFAULT CHARSET="
+
options
.
charset
:
""
)
charset
:
(
options
.
charset
?
"DEFAULT CHARSET="
+
options
.
charset
:
""
)
}
}
,
pkString
=
primaryKeys
.
map
(
function
(
pk
)
{
return
Utils
.
addTicks
(
pk
)
}).
join
(
", "
)
if
(
pkString
.
length
>
0
)
{
values
.
attributes
+=
", PRIMARY KEY ("
+
pkString
+
")"
}
return
Utils
.
_
.
template
(
query
)(
values
).
trim
()
+
";"
return
Utils
.
_
.
template
(
query
)(
values
).
trim
()
+
";"
},
},
...
@@ -112,16 +123,26 @@ module.exports = (function() {
...
@@ -112,16 +123,26 @@ module.exports = (function() {
var
template
=
"<%= type %>"
var
template
=
"<%= type %>"
,
replacements
=
{
type
:
dataType
.
type
}
,
replacements
=
{
type
:
dataType
.
type
}
if
(
dataType
.
hasOwnProperty
(
'allowNull'
)
&&
!
dataType
.
allowNull
&&
!
dataType
.
primaryKey
)
if
(
dataType
.
hasOwnProperty
(
'allowNull'
)
&&
!
dataType
.
allowNull
&&
!
dataType
.
primaryKey
)
{
template
+=
" NOT NULL"
template
+=
" NOT NULL"
}
if
(
dataType
.
defaultValue
!=
undefined
)
{
if
(
dataType
.
defaultValue
!=
undefined
)
{
template
+=
" DEFAULT <%= defaultValue %>"
template
+=
" DEFAULT <%= defaultValue %>"
replacements
.
defaultValue
=
Utils
.
escape
(
dataType
.
defaultValue
)
replacements
.
defaultValue
=
Utils
.
escape
(
dataType
.
defaultValue
)
}
}
if
(
dataType
.
unique
)
template
+=
" UNIQUE"
if
(
dataType
.
unique
)
{
if
(
dataType
.
primaryKey
)
template
+=
" PRIMARY KEY"
template
+=
" UNIQUE"
}
if
(
dataType
.
primaryKey
)
{
template
+=
" PRIMARY KEY"
if
(
dataType
.
autoIncrement
)
{
template
+=
' AUTOINCREMENT'
}
}
result
[
name
]
=
Utils
.
_
.
template
(
template
)(
replacements
)
result
[
name
]
=
Utils
.
_
.
template
(
template
)(
replacements
)
}
else
{
}
else
{
...
@@ -139,7 +160,7 @@ module.exports = (function() {
...
@@ -139,7 +160,7 @@ module.exports = (function() {
if
(
factory
.
attributes
.
hasOwnProperty
(
name
))
{
if
(
factory
.
attributes
.
hasOwnProperty
(
name
))
{
var
definition
=
factory
.
attributes
[
name
]
var
definition
=
factory
.
attributes
[
name
]
if
(
definition
&&
(
definition
.
indexOf
(
'INTEGER PRIMARY KEY'
)
===
0
))
{
if
(
definition
&&
(
definition
.
indexOf
(
'INTEGER PRIMARY KEY
AUTOINCREMENT
'
)
===
0
))
{
fields
.
push
(
name
)
fields
.
push
(
name
)
}
}
}
}
...
...
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