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
Hide 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 = {
'ORDER NULLS'
:
false
,
'UNION'
:
true
,
'UNION ALL'
:
true
,
/* What is the dialect's keyword for INSERT IGNORE */
'IGNORE'
:
''
,
/* does the dialect support returning values for inserted/updated fields */
returnValues
:
false
,
...
...
@@ -30,10 +28,6 @@ AbstractDialect.prototype.supports = {
},
/* Do we need to say DEFAULT for bulk insert */
bulkDefault
:
false
,
/* The dialect's words for INSERT IGNORE */
ignoreDuplicates
:
''
,
/* Does the dialect support ON DUPLICATE KEY UPDATE */
updateOnDuplicate
:
false
,
schemas
:
false
,
transactions
:
true
,
transactionOptions
:
{
...
...
@@ -41,6 +35,10 @@ AbstractDialect.prototype.supports = {
},
migrations
:
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
:
{
restrict
:
true
,
addConstraint
:
true
,
...
...
lib/dialects/abstract/query-generator.js
View file @
b00148e
...
...
@@ -232,7 +232,7 @@ class QueryGenerator {
}
const
replacements
=
{
ignoreDuplicates
:
options
.
ignoreDuplicates
?
this
.
_dialect
.
supports
.
IGNORE
:
''
,
ignoreDuplicates
:
options
.
ignoreDuplicates
?
this
.
_dialect
.
supports
.
inserts
.
ignoreDuplicates
:
''
,
table
:
this
.
quoteTable
(
table
),
attributes
:
fields
.
join
(
','
),
output
:
outputFragment
,
...
...
@@ -307,7 +307,7 @@ class QueryGenerator {
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
=>
{
const
key
=
this
.
quoteIdentifier
(
attr
);
return
key
+
'=VALUES('
+
key
+
')'
;
...
...
@@ -315,7 +315,7 @@ class QueryGenerator {
}
const
replacements
=
{
ignoreDuplicates
:
options
.
ignoreDuplicates
?
this
.
_dialect
.
supports
.
ignoreDuplicates
:
''
,
ignoreDuplicates
:
options
.
ignoreDuplicates
?
this
.
_dialect
.
supports
.
i
nserts
.
i
gnoreDuplicates
:
''
,
table
:
this
.
quoteTable
(
tableName
),
attributes
:
allAttributes
.
map
(
attr
=>
this
.
quoteIdentifier
(
attr
)).
join
(
','
),
tuples
:
tuples
.
join
(
','
),
...
...
lib/dialects/mssql/index.js
View file @
b00148e
...
...
@@ -27,7 +27,6 @@ MssqlDialect.prototype.supports = _.merge(_.cloneDeep(AbstractDialect.prototype.
lock
:
false
,
transactions
:
true
,
migrations
:
false
,
upserts
:
true
,
returnValues
:
{
output
:
true
},
...
...
lib/dialects/mysql/index.js
View file @
b00148e
...
...
@@ -22,9 +22,12 @@ class MysqlDialect extends AbstractDialect {
MysqlDialect
.
prototype
.
supports
=
_
.
merge
(
_
.
cloneDeep
(
AbstractDialect
.
prototype
.
supports
),
{
'VALUES ()'
:
true
,
'LIMIT ON UPDATE'
:
true
,
'IGNORE'
:
' IGNORE'
,
lock
:
true
,
forShare
:
'LOCK IN SHARE MODE'
,
inserts
:
{
ignoreDuplicates
:
' IGNORE'
,
updateOnDuplicate
:
true
},
index
:
{
collate
:
false
,
length
:
true
,
...
...
@@ -36,8 +39,6 @@ MysqlDialect.prototype.supports = _.merge(_.cloneDeep(AbstractDialect.prototype.
dropConstraint
:
false
,
check
:
false
},
ignoreDuplicates
:
' IGNORE'
,
updateOnDuplicate
:
true
,
indexViaAlter
:
true
,
NUMERIC
:
true
,
GEOMETRY
:
true
,
...
...
lib/dialects/sqlite/index.js
View file @
b00148e
...
...
@@ -23,7 +23,9 @@ SqliteDialect.prototype.supports = _.merge(_.cloneDeep(AbstractDialect.prototype
'DEFAULT'
:
false
,
'DEFAULT VALUES'
:
true
,
'UNION ALL'
:
false
,
'IGNORE'
:
' OR IGNORE'
,
inserts
:
{
ignoreDuplicates
:
' OR IGNORE'
},
index
:
{
using
:
false
,
where
:
true
...
...
@@ -38,7 +40,6 @@ SqliteDialect.prototype.supports = _.merge(_.cloneDeep(AbstractDialect.prototype
},
joinTableDependent
:
false
,
groupedLimit
:
false
,
ignoreDuplicates
:
' OR IGNORE'
,
JSON
:
true
});
...
...
test/integration/model/bulk-create.test.js
View file @
b00148e
...
...
@@ -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
()
{
const
self
=
this
;
const
data
=
[
...
...
@@ -436,7 +436,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
}
if
(
current
.
dialect
.
supports
.
updateOnDuplicate
)
{
if
(
current
.
dialect
.
supports
.
inserts
.
updateOnDuplicate
)
{
describe
(
'updateOnDuplicate'
,
()
=>
{
it
(
'should support the updateOnDuplicate option'
,
function
()
{
const
data
=
[
...
...
test/integration/model/upsert.test.js
View file @
b00148e
...
...
@@ -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'
,
{
username
:
{
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