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 fd080235
authored
Sep 27, 2019
by
Gal Jozsef
Committed by
Sushant
Sep 27, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: sequelize.where col not null (#11447) (#11454)
1 parent
22d874c3
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
54 additions
and
3 deletions
lib/dialects/abstract/query-generator.js
lib/utils.js
test/unit/dialects/abstract/query-generator.test.js
test/unit/sql/where.test.js
test/unit/utils.test.js
lib/dialects/abstract/query-generator.js
View file @
fd08023
...
...
@@ -2070,7 +2070,16 @@ class QueryGenerator {
if (value && value instanceof Utils.SequelizeMethod) {
value = this.getWhereConditions(value, tableName, factory, options, prepend);
return value === 'NULL' ? `
$
{
key
}
IS
NULL
` : [key, value].join(`
$
{
smth
.
comparator
}
`);
if (value === 'NULL') {
if (smth.comparator === '=') {
smth.comparator = 'IS';
}
if (smth.comparator === '!=') {
smth.comparator = 'IS NOT';
}
}
return [key, value].join(`
$
{
smth
.
comparator
}
`);
}
if (_.isPlainObject(value)) {
return this.whereItemQuery(smth.attribute, value, {
...
...
@@ -2083,7 +2092,16 @@ class QueryGenerator {
value = this.escape(value);
}
return value === 'NULL' ? `
$
{
key
}
IS
NULL
` : [key, value].join(`
$
{
smth
.
comparator
}
`);
if (value === 'NULL') {
if (smth.comparator === '=') {
smth.comparator = 'IS';
}
if (smth.comparator === '!=') {
smth.comparator = 'IS NOT';
}
}
return [key, value].join(`
$
{
smth
.
comparator
}
`);
}
if (smth instanceof Utils.Literal) {
return smth.val;
...
...
lib/utils.js
View file @
fd08023
...
...
@@ -239,7 +239,7 @@ function isColString(value) {
exports
.
isColString
=
isColString
;
function
canTreatArrayAsAnd
(
arr
)
{
return
arr
.
some
(
arg
=>
_
.
isPlainObject
(
arg
));
return
arr
.
some
(
arg
=>
_
.
isPlainObject
(
arg
)
||
arg
instanceof
Where
);
}
exports
.
canTreatArrayAsAnd
=
canTreatArrayAsAnd
;
...
...
test/unit/dialects/abstract/query-generator.test.js
View file @
fd08023
...
...
@@ -91,6 +91,12 @@ describe('QueryGenerator', () => {
const
QG
=
getAbstractQueryGenerator
(
this
.
sequelize
);
QG
.
handleSequelizeMethod
(
this
.
sequelize
.
where
(
this
.
sequelize
.
col
(
'foo'
),
'LIKE'
,
this
.
sequelize
.
col
(
'bar'
)))
.
should
.
be
.
equal
(
'foo LIKE bar'
);
QG
.
handleSequelizeMethod
(
this
.
sequelize
.
where
(
this
.
sequelize
.
col
(
'foo'
),
Op
.
ne
,
null
))
.
should
.
be
.
equal
(
'foo IS NOT NULL'
);
QG
.
handleSequelizeMethod
(
this
.
sequelize
.
where
(
this
.
sequelize
.
col
(
'foo'
),
Op
.
not
,
null
))
.
should
.
be
.
equal
(
'foo IS NOT NULL'
);
});
});
...
...
test/unit/sql/where.test.js
View file @
fd08023
...
...
@@ -1193,5 +1193,18 @@ describe(Support.getTestDialectTeaser('SQL'), () => {
testsql
(
current
.
where
(
current
.
fn
(
'SUM'
,
current
.
col
(
'hours'
)),
Op
.
gt
,
0
),
{
default
:
'SUM([hours]) > 0'
});
testsql
(
current
.
where
(
current
.
fn
(
'lower'
,
current
.
col
(
'name'
)),
Op
.
ne
,
null
),
{
default
:
'lower([name]) IS NOT NULL'
});
testsql
(
current
.
where
(
current
.
fn
(
'lower'
,
current
.
col
(
'name'
)),
Op
.
not
,
null
),
{
default
:
'lower([name]) IS NOT NULL'
});
testsql
([
current
.
where
(
current
.
fn
(
'SUM'
,
current
.
col
(
'hours'
)),
Op
.
gt
,
0
),
current
.
where
(
current
.
fn
(
'lower'
,
current
.
col
(
'name'
)),
null
)],
{
default
:
'(SUM([hours]) > 0 AND lower([name]) IS NULL)'
});
});
});
test/unit/utils.test.js
View file @
fd08023
...
...
@@ -20,6 +20,20 @@ describe(Support.getTestDialectTeaser('Utils'), () => {
});
});
describe
(
'canTreatArrayAsAnd'
,
()
=>
{
it
(
'Array can be treated as and'
,
()
=>
{
expect
(
Utils
.
canTreatArrayAsAnd
([{
'uuid'
:
1
}])).
to
.
equal
(
true
);
expect
(
Utils
.
canTreatArrayAsAnd
([{
'uuid'
:
1
},
{
'uuid'
:
2
},
1
])).
to
.
equal
(
true
);
expect
(
Utils
.
canTreatArrayAsAnd
([
new
Utils
.
Where
(
'uuid'
,
1
)])).
to
.
equal
(
true
);
expect
(
Utils
.
canTreatArrayAsAnd
([
new
Utils
.
Where
(
'uuid'
,
1
),
new
Utils
.
Where
(
'uuid'
,
2
)])).
to
.
equal
(
true
);
expect
(
Utils
.
canTreatArrayAsAnd
([
new
Utils
.
Where
(
'uuid'
,
1
),
{
'uuid'
:
2
},
1
])).
to
.
equal
(
true
);
});
it
(
'Array cannot be treated as and'
,
()
=>
{
expect
(
Utils
.
canTreatArrayAsAnd
([
1
,
'uuid'
])).
to
.
equal
(
false
);
expect
(
Utils
.
canTreatArrayAsAnd
([
1
])).
to
.
equal
(
false
);
});
});
describe
(
'toDefaultValue'
,
()
=>
{
it
(
'return plain data types'
,
()
=>
{
expect
(
Utils
.
toDefaultValue
(
DataTypes
.
UUIDV4
)).
to
.
equal
(
'UUIDV4'
);
...
...
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