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 6fb74c8a
authored
May 02, 2020
by
Sushant
Committed by
GitHub
May 02, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(query-generator): handle literal for substring based operators (#12210)
1 parent
8d9e58b4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
7 deletions
lib/dialects/abstract/query-generator.js
test/unit/sql/where.test.js
lib/dialects/abstract/query-generator.js
View file @
6fb74c8
...
...
@@ -425,7 +425,7 @@ class QueryGenerator {
* @param {object} incrementAmountsByField A plain-object with attribute-value-pairs
* @param {object} extraAttributesToBeUpdated A plain-object with attribute-value-pairs
* @param {object} options
*
*
* @private
*/
arithmeticQuery
(
operator
,
tableName
,
where
,
incrementAmountsByField
,
extraAttributesToBeUpdated
,
options
)
{
...
...
@@ -1724,7 +1724,7 @@ class QueryGenerator {
if (this.options.minifyAliases && asRight.length > 63) {
const alias = `
%
$
{
topLevelInfo
.
options
.
includeAliases
.
size
}
`;
topLevelInfo.options.includeAliases.set(alias, asRight);
}
...
...
@@ -2593,14 +2593,20 @@ class QueryGenerator {
return
this
.
_joinKeyValue
(
key
,
value
.
map
(
identifier
=>
this
.
quoteIdentifier
(
identifier
)).
join
(
'.'
),
comparator
,
options
.
prefix
);
case
Op
.
startsWith
:
comparator
=
this
.
OperatorMap
[
Op
.
like
];
return
this
.
_joinKeyValue
(
key
,
this
.
escape
(
`
${
value
}
%`
),
comparator
,
options
.
prefix
);
case
Op
.
endsWith
:
comparator
=
this
.
OperatorMap
[
Op
.
like
];
return
this
.
_joinKeyValue
(
key
,
this
.
escape
(
`%
${
value
}
`
),
comparator
,
options
.
prefix
);
case
Op
.
substring
:
comparator
=
this
.
OperatorMap
[
Op
.
like
];
return
this
.
_joinKeyValue
(
key
,
this
.
escape
(
`%
${
value
}
%`
),
comparator
,
options
.
prefix
);
if
(
value
instanceof
Utils
.
Literal
)
{
value
=
value
.
val
;
}
let
pattern
=
`
${
value
}
%`
;
if
(
prop
===
Op
.
endsWith
)
pattern
=
`%
${
value
}
`
;
if
(
prop
===
Op
.
substring
)
pattern
=
`%
${
value
}
%`
;
return
this
.
_joinKeyValue
(
key
,
this
.
escape
(
pattern
),
comparator
,
options
.
prefix
);
}
const
escapeOptions
=
{
...
...
test/unit/sql/where.test.js
View file @
6fb74c8
...
...
@@ -441,6 +441,13 @@ describe(Support.getTestDialectTeaser('SQL'), () => {
default
:
"[username] LIKE 'swagger%'"
,
mssql
:
"[username] LIKE N'swagger%'"
});
testsql
(
'username'
,
{
[
Op
.
startsWith
]:
current
.
literal
(
'swagger'
)
},
{
default
:
"[username] LIKE 'swagger%'"
,
mssql
:
"[username] LIKE N'swagger%'"
});
});
describe
(
'Op.endsWith'
,
()
=>
{
...
...
@@ -450,6 +457,13 @@ describe(Support.getTestDialectTeaser('SQL'), () => {
default
:
"[username] LIKE '%swagger'"
,
mssql
:
"[username] LIKE N'%swagger'"
});
testsql
(
'username'
,
{
[
Op
.
endsWith
]:
current
.
literal
(
'swagger'
)
},
{
default
:
"[username] LIKE '%swagger'"
,
mssql
:
"[username] LIKE N'%swagger'"
});
});
describe
(
'Op.substring'
,
()
=>
{
...
...
@@ -459,6 +473,13 @@ describe(Support.getTestDialectTeaser('SQL'), () => {
default
:
"[username] LIKE '%swagger%'"
,
mssql
:
"[username] LIKE N'%swagger%'"
});
testsql
(
'username'
,
{
[
Op
.
substring
]:
current
.
literal
(
'swagger'
)
},
{
default
:
"[username] LIKE '%swagger%'"
,
mssql
:
"[username] LIKE N'%swagger%'"
});
});
describe
(
'Op.between'
,
()
=>
{
...
...
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