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 8b20a45a
authored
Sep 08, 2017
by
Ilia Ermolin
Committed by
Sushant
Sep 08, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(instance/decrement): doesn't work with negative value (#8267)
1 parent
e41590af
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
53 additions
and
17 deletions
lib/dialects/abstract/query-generator.js
test/integration/instance.test.js
test/unit/dialects/mssql/query-generator.test.js
test/unit/dialects/mysql/query-generator.test.js
test/unit/dialects/postgres/query-generator.test.js
test/unit/dialects/sqlite/query-generator.test.js
lib/dialects/abstract/query-generator.js
View file @
8b20a45
...
@@ -403,7 +403,7 @@ const QueryGenerator = {
...
@@ -403,7 +403,7 @@ const QueryGenerator = {
for
(
const
key
in
attrValueHash
)
{
for
(
const
key
in
attrValueHash
)
{
const
value
=
attrValueHash
[
key
];
const
value
=
attrValueHash
[
key
];
values
.
push
(
this
.
quoteIdentifier
(
key
)
+
'='
+
this
.
quoteIdentifier
(
key
)
+
operator
+
this
.
escape
(
value
));
values
.
push
(
this
.
quoteIdentifier
(
key
)
+
'='
+
this
.
quoteIdentifier
(
key
)
+
operator
+
' '
+
this
.
escape
(
value
));
}
}
attributes
=
attributes
||
{};
attributes
=
attributes
||
{};
...
...
test/integration/instance.test.js
View file @
8b20a45
...
@@ -398,6 +398,22 @@ describe(Support.getTestDialectTeaser('Instance'), () => {
...
@@ -398,6 +398,22 @@ describe(Support.getTestDialectTeaser('Instance'), () => {
});
});
});
});
it
(
'with negative value'
,
function
()
{
const
self
=
this
;
return
this
.
User
.
findById
(
1
).
then
(
user1
=>
{
return
self
.
sequelize
.
Promise
.
all
([
user1
.
decrement
(
'aNumber'
,
{
by
:
-
2
}),
user1
.
decrement
([
'aNumber'
,
'bNumber'
],
{
by
:
-
2
}),
user1
.
decrement
({
'aNumber'
:
-
1
,
'bNumber'
:
-
2
}),
]).
then
(()
=>
{
return
self
.
User
.
findById
(
1
).
then
(
user3
=>
{
expect
(
user3
.
aNumber
).
to
.
be
.
equal
(
+
5
);
expect
(
user3
.
bNumber
).
to
.
be
.
equal
(
+
4
);
});
});
});
});
it
(
'with timestamps set to true'
,
function
()
{
it
(
'with timestamps set to true'
,
function
()
{
const
User
=
this
.
sequelize
.
define
(
'IncrementUser'
,
{
const
User
=
this
.
sequelize
.
define
(
'IncrementUser'
,
{
aNumber
:
DataTypes
.
INTEGER
aNumber
:
DataTypes
.
INTEGER
...
...
test/unit/dialects/mssql/query-generator.test.js
View file @
8b20a45
...
@@ -175,22 +175,27 @@ if (current.dialect.name === 'mssql') {
...
@@ -175,22 +175,27 @@ if (current.dialect.name === 'mssql') {
[{
[{
title
:
'Should use the plus operator'
,
title
:
'Should use the plus operator'
,
arguments
:
[
'+'
,
'myTable'
,
{
foo
:
'bar'
},
{},
{}],
arguments
:
[
'+'
,
'myTable'
,
{
foo
:
'bar'
},
{},
{}],
expectation
:
'UPDATE myTable SET foo=foo+\'bar\' '
expectation
:
'UPDATE myTable SET foo=foo+
\'bar\' '
},
},
{
{
title
:
'Should use the plus operator with where clause'
,
title
:
'Should use the plus operator with where clause'
,
arguments
:
[
'+'
,
'myTable'
,
{
foo
:
'bar'
},
{
bar
:
'biz'
},
{}],
arguments
:
[
'+'
,
'myTable'
,
{
foo
:
'bar'
},
{
bar
:
'biz'
},
{}],
expectation
:
'UPDATE myTable SET foo=foo+\'bar\' WHERE bar = \'biz\''
expectation
:
'UPDATE myTable SET foo=foo+
\'bar\' WHERE bar = \'biz\''
},
},
{
{
title
:
'Should use the minus operator'
,
title
:
'Should use the minus operator'
,
arguments
:
[
'-'
,
'myTable'
,
{
foo
:
'bar'
},
{},
{}],
arguments
:
[
'-'
,
'myTable'
,
{
foo
:
'bar'
},
{},
{}],
expectation
:
'UPDATE myTable SET foo=foo-\'bar\' '
expectation
:
'UPDATE myTable SET foo=foo- \'bar\' '
},
{
title
:
'Should use the minus operator with negative value'
,
arguments
:
[
'-'
,
'myTable'
,
{
foo
:
-
1
},
{},
{}],
expectation
:
'UPDATE myTable SET foo=foo- -1 '
},
},
{
{
title
:
'Should use the minus operator with where clause'
,
title
:
'Should use the minus operator with where clause'
,
arguments
:
[
'-'
,
'myTable'
,
{
foo
:
'bar'
},
{
bar
:
'biz'
},
{}],
arguments
:
[
'-'
,
'myTable'
,
{
foo
:
'bar'
},
{
bar
:
'biz'
},
{}],
expectation
:
'UPDATE myTable SET foo=foo-\'bar\' WHERE bar = \'biz\''
expectation
:
'UPDATE myTable SET foo=foo-
\'bar\' WHERE bar = \'biz\''
}].
forEach
(
test
=>
{
}].
forEach
(
test
=>
{
it
(
test
.
title
,
()
=>
{
it
(
test
.
title
,
()
=>
{
expectsql
(
QueryGenerator
.
arithmeticQuery
.
call
(
QueryGenerator
,
test
.
arguments
),
{
expectsql
(
QueryGenerator
.
arithmeticQuery
.
call
(
QueryGenerator
,
test
.
arguments
),
{
...
...
test/unit/dialects/mysql/query-generator.test.js
View file @
8b20a45
...
@@ -14,22 +14,27 @@ if (dialect === 'mysql') {
...
@@ -14,22 +14,27 @@ if (dialect === 'mysql') {
{
{
title
:
'Should use the plus operator'
,
title
:
'Should use the plus operator'
,
arguments
:
[
'+'
,
'myTable'
,
{
foo
:
'bar'
},
{},
{}],
arguments
:
[
'+'
,
'myTable'
,
{
foo
:
'bar'
},
{},
{}],
expectation
:
'UPDATE `myTable` SET `foo`=`foo`+\'bar\' '
expectation
:
'UPDATE `myTable` SET `foo`=`foo`+
\'bar\' '
},
},
{
{
title
:
'Should use the plus operator with where clause'
,
title
:
'Should use the plus operator with where clause'
,
arguments
:
[
'+'
,
'myTable'
,
{
foo
:
'bar'
},
{
bar
:
'biz'
},
{}],
arguments
:
[
'+'
,
'myTable'
,
{
foo
:
'bar'
},
{
bar
:
'biz'
},
{}],
expectation
:
'UPDATE `myTable` SET `foo`=`foo`+\'bar\' WHERE `bar` = \'biz\''
expectation
:
'UPDATE `myTable` SET `foo`=`foo`+
\'bar\' WHERE `bar` = \'biz\''
},
},
{
{
title
:
'Should use the minus operator'
,
title
:
'Should use the minus operator'
,
arguments
:
[
'-'
,
'myTable'
,
{
foo
:
'bar'
},
{},
{}],
arguments
:
[
'-'
,
'myTable'
,
{
foo
:
'bar'
},
{},
{}],
expectation
:
'UPDATE `myTable` SET `foo`=`foo`-\'bar\' '
expectation
:
'UPDATE `myTable` SET `foo`=`foo`- \'bar\' '
},
{
title
:
'Should use the minus operator with negative value'
,
arguments
:
[
'-'
,
'myTable'
,
{
foo
:
-
1
},
{},
{}],
expectation
:
'UPDATE `myTable` SET `foo`=`foo`- -1 '
},
},
{
{
title
:
'Should use the minus operator with where clause'
,
title
:
'Should use the minus operator with where clause'
,
arguments
:
[
'-'
,
'myTable'
,
{
foo
:
'bar'
},
{
bar
:
'biz'
},
{}],
arguments
:
[
'-'
,
'myTable'
,
{
foo
:
'bar'
},
{
bar
:
'biz'
},
{}],
expectation
:
'UPDATE `myTable` SET `foo`=`foo`-\'bar\' WHERE `bar` = \'biz\''
expectation
:
'UPDATE `myTable` SET `foo`=`foo`-
\'bar\' WHERE `bar` = \'biz\''
}
}
],
],
attributesToSQL
:
[
attributesToSQL
:
[
...
...
test/unit/dialects/postgres/query-generator.test.js
View file @
8b20a45
...
@@ -17,22 +17,27 @@ if (dialect.match(/^postgres/)) {
...
@@ -17,22 +17,27 @@ if (dialect.match(/^postgres/)) {
{
{
title
:
'Should use the plus operator'
,
title
:
'Should use the plus operator'
,
arguments
:
[
'+'
,
'myTable'
,
{
foo
:
'bar'
},
{},
{}],
arguments
:
[
'+'
,
'myTable'
,
{
foo
:
'bar'
},
{},
{}],
expectation
:
'UPDATE "myTable" SET "foo"="foo"+\'bar\' RETURNING *'
expectation
:
'UPDATE "myTable" SET "foo"="foo"+
\'bar\' RETURNING *'
},
},
{
{
title
:
'Should use the plus operator with where clause'
,
title
:
'Should use the plus operator with where clause'
,
arguments
:
[
'+'
,
'myTable'
,
{
foo
:
'bar'
},
{
bar
:
'biz'
},
{}],
arguments
:
[
'+'
,
'myTable'
,
{
foo
:
'bar'
},
{
bar
:
'biz'
},
{}],
expectation
:
'UPDATE "myTable" SET "foo"="foo"+\'bar\' WHERE "bar" = \'biz\' RETURNING *'
expectation
:
'UPDATE "myTable" SET "foo"="foo"+
\'bar\' WHERE "bar" = \'biz\' RETURNING *'
},
},
{
{
title
:
'Should use the minus operator'
,
title
:
'Should use the minus operator'
,
arguments
:
[
'-'
,
'myTable'
,
{
foo
:
'bar'
},
{},
{}],
arguments
:
[
'-'
,
'myTable'
,
{
foo
:
'bar'
},
{},
{}],
expectation
:
'UPDATE "myTable" SET "foo"="foo"-\'bar\' RETURNING *'
expectation
:
'UPDATE "myTable" SET "foo"="foo"- \'bar\' RETURNING *'
},
{
title
:
'Should use the minus operator with negative value'
,
arguments
:
[
'-'
,
'myTable'
,
{
foo
:
-
1
},
{},
{}],
expectation
:
'UPDATE "myTable" SET "foo"="foo"- -1 RETURNING *'
},
},
{
{
title
:
'Should use the minus operator with where clause'
,
title
:
'Should use the minus operator with where clause'
,
arguments
:
[
'-'
,
'myTable'
,
{
foo
:
'bar'
},
{
bar
:
'biz'
},
{}],
arguments
:
[
'-'
,
'myTable'
,
{
foo
:
'bar'
},
{
bar
:
'biz'
},
{}],
expectation
:
'UPDATE "myTable" SET "foo"="foo"-\'bar\' WHERE "bar" = \'biz\' RETURNING *'
expectation
:
'UPDATE "myTable" SET "foo"="foo"-
\'bar\' WHERE "bar" = \'biz\' RETURNING *'
}
}
],
],
attributesToSQL
:
[
attributesToSQL
:
[
...
...
test/unit/dialects/sqlite/query-generator.test.js
View file @
8b20a45
...
@@ -23,22 +23,27 @@ if (dialect === 'sqlite') {
...
@@ -23,22 +23,27 @@ if (dialect === 'sqlite') {
{
{
title
:
'Should use the plus operator'
,
title
:
'Should use the plus operator'
,
arguments
:
[
'+'
,
'myTable'
,
{
foo
:
'bar'
},
{}],
arguments
:
[
'+'
,
'myTable'
,
{
foo
:
'bar'
},
{}],
expectation
:
'UPDATE `myTable` SET `foo`=`foo`+\'bar\' '
expectation
:
'UPDATE `myTable` SET `foo`=`foo`+
\'bar\' '
},
},
{
{
title
:
'Should use the plus operator with where clause'
,
title
:
'Should use the plus operator with where clause'
,
arguments
:
[
'+'
,
'myTable'
,
{
foo
:
'bar'
},
{
bar
:
'biz'
}],
arguments
:
[
'+'
,
'myTable'
,
{
foo
:
'bar'
},
{
bar
:
'biz'
}],
expectation
:
'UPDATE `myTable` SET `foo`=`foo`+\'bar\' WHERE `bar` = \'biz\''
expectation
:
'UPDATE `myTable` SET `foo`=`foo`+
\'bar\' WHERE `bar` = \'biz\''
},
},
{
{
title
:
'Should use the minus operator'
,
title
:
'Should use the minus operator'
,
arguments
:
[
'-'
,
'myTable'
,
{
foo
:
'bar'
}],
arguments
:
[
'-'
,
'myTable'
,
{
foo
:
'bar'
}],
expectation
:
'UPDATE `myTable` SET `foo`=`foo`-\'bar\' '
expectation
:
'UPDATE `myTable` SET `foo`=`foo`- \'bar\' '
},
{
title
:
'Should use the minus operator with negative value'
,
arguments
:
[
'-'
,
'myTable'
,
{
foo
:
-
1
}],
expectation
:
'UPDATE `myTable` SET `foo`=`foo`- -1 '
},
},
{
{
title
:
'Should use the minus operator with where clause'
,
title
:
'Should use the minus operator with where clause'
,
arguments
:
[
'-'
,
'myTable'
,
{
foo
:
'bar'
},
{
bar
:
'biz'
}],
arguments
:
[
'-'
,
'myTable'
,
{
foo
:
'bar'
},
{
bar
:
'biz'
}],
expectation
:
'UPDATE `myTable` SET `foo`=`foo`-\'bar\' WHERE `bar` = \'biz\''
expectation
:
'UPDATE `myTable` SET `foo`=`foo`-
\'bar\' WHERE `bar` = \'biz\''
}
}
],
],
attributesToSQL
:
[
attributesToSQL
:
[
...
...
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