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 b00148e0
authored
Jul 15, 2018
by
Sushant
Committed by
GitHub
Jul 15, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: dialect support information for inserts (#9663)
1 parent
735b2a48
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
17 additions
and
18 deletions
lib/dialects/abstract/index.js
lib/dialects/abstract/query-generator.js
lib/dialects/mssql/index.js
lib/dialects/mysql/index.js
lib/dialects/sqlite/index.js
test/integration/model/bulk-create.test.js
test/integration/model/upsert.test.js
lib/dialects/abstract/index.js
View file @
b00148e
...
@@ -11,8 +11,6 @@ AbstractDialect.prototype.supports = {
...
@@ -11,8 +11,6 @@ AbstractDialect.prototype.supports = {
'ORDER NULLS'
:
false
,
'ORDER NULLS'
:
false
,
'UNION'
:
true
,
'UNION'
:
true
,
'UNION ALL'
:
true
,
'UNION ALL'
:
true
,
/* What is the dialect's keyword for INSERT IGNORE */
'IGNORE'
:
''
,
/* does the dialect support returning values for inserted/updated fields */
/* does the dialect support returning values for inserted/updated fields */
returnValues
:
false
,
returnValues
:
false
,
...
@@ -30,10 +28,6 @@ AbstractDialect.prototype.supports = {
...
@@ -30,10 +28,6 @@ AbstractDialect.prototype.supports = {
},
},
/* Do we need to say DEFAULT for bulk insert */
/* Do we need to say DEFAULT for bulk insert */
bulkDefault
:
false
,
bulkDefault
:
false
,
/* The dialect's words for INSERT IGNORE */
ignoreDuplicates
:
''
,
/* Does the dialect support ON DUPLICATE KEY UPDATE */
updateOnDuplicate
:
false
,
schemas
:
false
,
schemas
:
false
,
transactions
:
true
,
transactions
:
true
,
transactionOptions
:
{
transactionOptions
:
{
...
@@ -41,6 +35,10 @@ AbstractDialect.prototype.supports = {
...
@@ -41,6 +35,10 @@ AbstractDialect.prototype.supports = {
},
},
migrations
:
true
,
migrations
:
true
,
upserts
:
true
,
upserts
:
true
,
inserts
:
{
ignoreDuplicates
:
false
,
/* dialect specific words for INSERT IGNORE or DO NOTHING*/
updateOnDuplicate
:
false
/* dialect specific words for ON DUPLICATE KEY UPDATE or ON CONFLICT*/
},
constraints
:
{
constraints
:
{
restrict
:
true
,
restrict
:
true
,
addConstraint
:
true
,
addConstraint
:
true
,
...
...
lib/dialects/abstract/query-generator.js
View file @
b00148e
...
@@ -232,7 +232,7 @@ class QueryGenerator {
...
@@ -232,7 +232,7 @@ class QueryGenerator {
}
}
const
replacements
=
{
const
replacements
=
{
ignoreDuplicates
:
options
.
ignoreDuplicates
?
this
.
_dialect
.
supports
.
IGNORE
:
''
,
ignoreDuplicates
:
options
.
ignoreDuplicates
?
this
.
_dialect
.
supports
.
inserts
.
ignoreDuplicates
:
''
,
table
:
this
.
quoteTable
(
table
),
table
:
this
.
quoteTable
(
table
),
attributes
:
fields
.
join
(
','
),
attributes
:
fields
.
join
(
','
),
output
:
outputFragment
,
output
:
outputFragment
,
...
@@ -307,7 +307,7 @@ class QueryGenerator {
...
@@ -307,7 +307,7 @@ class QueryGenerator {
tuples
.
push
(
`(
${
values
.
join
(
','
)}
)`
);
tuples
.
push
(
`(
${
values
.
join
(
','
)}
)`
);
}
}
if
(
this
.
_dialect
.
supports
.
updateOnDuplicate
&&
options
.
updateOnDuplicate
)
{
if
(
this
.
_dialect
.
supports
.
inserts
.
updateOnDuplicate
&&
options
.
updateOnDuplicate
)
{
onDuplicateKeyUpdate
=
' ON DUPLICATE KEY UPDATE '
+
options
.
updateOnDuplicate
.
map
(
attr
=>
{
onDuplicateKeyUpdate
=
' ON DUPLICATE KEY UPDATE '
+
options
.
updateOnDuplicate
.
map
(
attr
=>
{
const
key
=
this
.
quoteIdentifier
(
attr
);
const
key
=
this
.
quoteIdentifier
(
attr
);
return
key
+
'=VALUES('
+
key
+
')'
;
return
key
+
'=VALUES('
+
key
+
')'
;
...
@@ -315,7 +315,7 @@ class QueryGenerator {
...
@@ -315,7 +315,7 @@ class QueryGenerator {
}
}
const
replacements
=
{
const
replacements
=
{
ignoreDuplicates
:
options
.
ignoreDuplicates
?
this
.
_dialect
.
supports
.
ignoreDuplicates
:
''
,
ignoreDuplicates
:
options
.
ignoreDuplicates
?
this
.
_dialect
.
supports
.
i
nserts
.
i
gnoreDuplicates
:
''
,
table
:
this
.
quoteTable
(
tableName
),
table
:
this
.
quoteTable
(
tableName
),
attributes
:
allAttributes
.
map
(
attr
=>
this
.
quoteIdentifier
(
attr
)).
join
(
','
),
attributes
:
allAttributes
.
map
(
attr
=>
this
.
quoteIdentifier
(
attr
)).
join
(
','
),
tuples
:
tuples
.
join
(
','
),
tuples
:
tuples
.
join
(
','
),
...
...
lib/dialects/mssql/index.js
View file @
b00148e
...
@@ -27,7 +27,6 @@ MssqlDialect.prototype.supports = _.merge(_.cloneDeep(AbstractDialect.prototype.
...
@@ -27,7 +27,6 @@ MssqlDialect.prototype.supports = _.merge(_.cloneDeep(AbstractDialect.prototype.
lock
:
false
,
lock
:
false
,
transactions
:
true
,
transactions
:
true
,
migrations
:
false
,
migrations
:
false
,
upserts
:
true
,
returnValues
:
{
returnValues
:
{
output
:
true
output
:
true
},
},
...
...
lib/dialects/mysql/index.js
View file @
b00148e
...
@@ -22,9 +22,12 @@ class MysqlDialect extends AbstractDialect {
...
@@ -22,9 +22,12 @@ class MysqlDialect extends AbstractDialect {
MysqlDialect
.
prototype
.
supports
=
_
.
merge
(
_
.
cloneDeep
(
AbstractDialect
.
prototype
.
supports
),
{
MysqlDialect
.
prototype
.
supports
=
_
.
merge
(
_
.
cloneDeep
(
AbstractDialect
.
prototype
.
supports
),
{
'VALUES ()'
:
true
,
'VALUES ()'
:
true
,
'LIMIT ON UPDATE'
:
true
,
'LIMIT ON UPDATE'
:
true
,
'IGNORE'
:
' IGNORE'
,
lock
:
true
,
lock
:
true
,
forShare
:
'LOCK IN SHARE MODE'
,
forShare
:
'LOCK IN SHARE MODE'
,
inserts
:
{
ignoreDuplicates
:
' IGNORE'
,
updateOnDuplicate
:
true
},
index
:
{
index
:
{
collate
:
false
,
collate
:
false
,
length
:
true
,
length
:
true
,
...
@@ -36,8 +39,6 @@ MysqlDialect.prototype.supports = _.merge(_.cloneDeep(AbstractDialect.prototype.
...
@@ -36,8 +39,6 @@ MysqlDialect.prototype.supports = _.merge(_.cloneDeep(AbstractDialect.prototype.
dropConstraint
:
false
,
dropConstraint
:
false
,
check
:
false
check
:
false
},
},
ignoreDuplicates
:
' IGNORE'
,
updateOnDuplicate
:
true
,
indexViaAlter
:
true
,
indexViaAlter
:
true
,
NUMERIC
:
true
,
NUMERIC
:
true
,
GEOMETRY
:
true
,
GEOMETRY
:
true
,
...
...
lib/dialects/sqlite/index.js
View file @
b00148e
...
@@ -23,7 +23,9 @@ SqliteDialect.prototype.supports = _.merge(_.cloneDeep(AbstractDialect.prototype
...
@@ -23,7 +23,9 @@ SqliteDialect.prototype.supports = _.merge(_.cloneDeep(AbstractDialect.prototype
'DEFAULT'
:
false
,
'DEFAULT'
:
false
,
'DEFAULT VALUES'
:
true
,
'DEFAULT VALUES'
:
true
,
'UNION ALL'
:
false
,
'UNION ALL'
:
false
,
'IGNORE'
:
' OR IGNORE'
,
inserts
:
{
ignoreDuplicates
:
' OR IGNORE'
},
index
:
{
index
:
{
using
:
false
,
using
:
false
,
where
:
true
where
:
true
...
@@ -38,7 +40,6 @@ SqliteDialect.prototype.supports = _.merge(_.cloneDeep(AbstractDialect.prototype
...
@@ -38,7 +40,6 @@ SqliteDialect.prototype.supports = _.merge(_.cloneDeep(AbstractDialect.prototype
},
},
joinTableDependent
:
false
,
joinTableDependent
:
false
,
groupedLimit
:
false
,
groupedLimit
:
false
,
ignoreDuplicates
:
' OR IGNORE'
,
JSON
:
true
JSON
:
true
});
});
...
...
test/integration/model/bulk-create.test.js
View file @
b00148e
...
@@ -395,7 +395,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
...
@@ -395,7 +395,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
});
});
});
if
(
current
.
dialect
.
supports
.
ignoreDuplicates
)
{
if
(
current
.
dialect
.
supports
.
i
nserts
.
i
gnoreDuplicates
)
{
it
(
'should support the ignoreDuplicates option'
,
function
()
{
it
(
'should support the ignoreDuplicates option'
,
function
()
{
const
self
=
this
;
const
self
=
this
;
const
data
=
[
const
data
=
[
...
@@ -436,7 +436,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
...
@@ -436,7 +436,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
});
}
}
if
(
current
.
dialect
.
supports
.
updateOnDuplicate
)
{
if
(
current
.
dialect
.
supports
.
inserts
.
updateOnDuplicate
)
{
describe
(
'updateOnDuplicate'
,
()
=>
{
describe
(
'updateOnDuplicate'
,
()
=>
{
it
(
'should support the updateOnDuplicate option'
,
function
()
{
it
(
'should support the updateOnDuplicate option'
,
function
()
{
const
data
=
[
const
data
=
[
...
...
test/integration/model/upsert.test.js
View file @
b00148e
...
@@ -370,7 +370,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
...
@@ -370,7 +370,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
});
});
});
it
(
'
W
orks when two separate uniqueKeys are passed'
,
function
()
{
it
(
'
w
orks when two separate uniqueKeys are passed'
,
function
()
{
const
User
=
this
.
sequelize
.
define
(
'User'
,
{
const
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
{
username
:
{
type
:
Sequelize
.
STRING
,
type
:
Sequelize
.
STRING
,
...
...
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