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

Commit e33462aa by Simon Schick Committed by Sushant

fix(querying): swap startWith and endsWith operators (#10753)

1 parent 0caf84b3
...@@ -162,8 +162,8 @@ const Op = Sequelize.Op ...@@ -162,8 +162,8 @@ const Op = Sequelize.Op
[Op.notLike]: '%hat' // NOT LIKE '%hat' [Op.notLike]: '%hat' // NOT LIKE '%hat'
[Op.iLike]: '%hat' // ILIKE '%hat' (case insensitive) (PG only) [Op.iLike]: '%hat' // ILIKE '%hat' (case insensitive) (PG only)
[Op.notILike]: '%hat' // NOT ILIKE '%hat' (PG only) [Op.notILike]: '%hat' // NOT ILIKE '%hat' (PG only)
[Op.startsWith]: 'hat' // LIKE '%hat' [Op.startsWith]: 'hat' // LIKE 'hat%'
[Op.endsWith]: 'hat' // LIKE 'hat%' [Op.endsWith]: 'hat' // LIKE '%hat'
[Op.substring]: 'hat' // LIKE '%hat%' [Op.substring]: 'hat' // LIKE '%hat%'
[Op.regexp]: '^[h|a|t]' // REGEXP/~ '^[h|a|t]' (MySQL/PG only) [Op.regexp]: '^[h|a|t]' // REGEXP/~ '^[h|a|t]' (MySQL/PG only)
[Op.notRegexp]: '^[h|a|t]' // NOT REGEXP/!~ '^[h|a|t]' (MySQL/PG only) [Op.notRegexp]: '^[h|a|t]' // NOT REGEXP/!~ '^[h|a|t]' (MySQL/PG only)
......
...@@ -2385,10 +2385,10 @@ class QueryGenerator { ...@@ -2385,10 +2385,10 @@ class QueryGenerator {
return this._joinKeyValue(key, value.map(identifier => this.quoteIdentifier(identifier)).join('.'), comparator, options.prefix); return this._joinKeyValue(key, value.map(identifier => this.quoteIdentifier(identifier)).join('.'), comparator, options.prefix);
case Op.startsWith: case Op.startsWith:
comparator = this.OperatorMap[Op.like]; comparator = this.OperatorMap[Op.like];
return this._joinKeyValue(key, this.escape(`%${value}`), comparator, options.prefix); return this._joinKeyValue(key, this.escape(`${value}%`), comparator, options.prefix);
case Op.endsWith: case Op.endsWith:
comparator = this.OperatorMap[Op.like]; comparator = this.OperatorMap[Op.like];
return this._joinKeyValue(key, this.escape(`${value}%`), comparator, options.prefix); return this._joinKeyValue(key, this.escape(`%${value}`), comparator, options.prefix);
case Op.substring: case Op.substring:
comparator = this.OperatorMap[Op.like]; comparator = this.OperatorMap[Op.like];
return this._joinKeyValue(key, this.escape(`%${value}%`), comparator, options.prefix); return this._joinKeyValue(key, this.escape(`%${value}%`), comparator, options.prefix);
......
...@@ -438,8 +438,8 @@ describe(Support.getTestDialectTeaser('SQL'), () => { ...@@ -438,8 +438,8 @@ describe(Support.getTestDialectTeaser('SQL'), () => {
testsql('username', { testsql('username', {
[Op.startsWith]: 'swagger' [Op.startsWith]: 'swagger'
}, { }, {
default: "[username] LIKE '%swagger'", default: "[username] LIKE 'swagger%'",
mssql: "[username] LIKE N'%swagger'" mssql: "[username] LIKE N'swagger%'"
}); });
}); });
...@@ -447,8 +447,8 @@ describe(Support.getTestDialectTeaser('SQL'), () => { ...@@ -447,8 +447,8 @@ describe(Support.getTestDialectTeaser('SQL'), () => {
testsql('username', { testsql('username', {
[Op.endsWith]: 'swagger' [Op.endsWith]: 'swagger'
}, { }, {
default: "[username] LIKE 'swagger%'", default: "[username] LIKE '%swagger'",
mssql: "[username] LIKE N'swagger%'" mssql: "[username] LIKE N'%swagger'"
}); });
}); });
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!