不要怂,就是干,撸起袖子干!

Commit b00148e0 by Sushant Committed by GitHub

refactor: dialect support information for inserts (#9663)

1 parent 735b2a48
......@@ -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,
......
......@@ -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.inserts.ignoreDuplicates : '',
table: this.quoteTable(tableName),
attributes: allAttributes.map(attr => this.quoteIdentifier(attr)).join(','),
tuples: tuples.join(','),
......
......@@ -27,7 +27,6 @@ MssqlDialect.prototype.supports = _.merge(_.cloneDeep(AbstractDialect.prototype.
lock: false,
transactions: true,
migrations: false,
upserts: true,
returnValues: {
output: true
},
......
......@@ -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,
......
......@@ -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
});
......
......@@ -395,7 +395,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
});
if (current.dialect.supports.ignoreDuplicates) {
if (current.dialect.supports.inserts.ignoreDuplicates) {
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 = [
......
......@@ -370,7 +370,7 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
});
it('Works when two separate uniqueKeys are passed', function() {
it('works when two separate uniqueKeys are passed', function() {
const User = this.sequelize.define('User', {
username: {
type: Sequelize.STRING,
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!