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 441ea3d8
authored
Nov 06, 2012
by
Sascha Depold
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'update_return' of
git://github.com/joshm/sequelize
into joshm-update_return
2 parents
a8f98af8
ca278d7e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
11 deletions
lib/dialects/postgres/query-generator.js
lib/dialects/postgres/query.js
spec-jasmine/postgres/query-generator.spec.js
lib/dialects/postgres/query-generator.js
View file @
441ea3d
...
@@ -274,7 +274,7 @@ module.exports = (function() {
...
@@ -274,7 +274,7 @@ module.exports = (function() {
updateQuery
:
function
(
tableName
,
attrValueHash
,
where
)
{
updateQuery
:
function
(
tableName
,
attrValueHash
,
where
)
{
attrValueHash
=
Utils
.
removeNullValuesFromHash
(
attrValueHash
,
this
.
options
.
omitNull
)
attrValueHash
=
Utils
.
removeNullValuesFromHash
(
attrValueHash
,
this
.
options
.
omitNull
)
var
query
=
"UPDATE <%= table %> SET <%= values %> WHERE <%= where %>"
var
query
=
"UPDATE <%= table %> SET <%= values %> WHERE <%= where %>
RETURNING *
"
,
values
=
[]
,
values
=
[]
for
(
var
key
in
attrValueHash
)
{
for
(
var
key
in
attrValueHash
)
{
...
...
lib/dialects/postgres/query.js
View file @
441ea3d
...
@@ -75,6 +75,12 @@ module.exports = (function() {
...
@@ -75,6 +75,12 @@ module.exports = (function() {
this
.
emit
(
'success'
,
this
.
callee
)
this
.
emit
(
'success'
,
this
.
callee
)
}
else
if
(
this
.
send
(
'isUpdateQuery'
))
{
}
else
if
(
this
.
send
(
'isUpdateQuery'
))
{
for
(
var
key
in
rows
[
0
])
{
if
(
rows
[
0
].
hasOwnProperty
(
key
))
{
this
.
callee
[
key
]
=
rows
[
0
][
key
]
}
}
this
.
emit
(
'success'
,
this
.
callee
)
this
.
emit
(
'success'
,
this
.
callee
)
}
else
{
}
else
{
this
.
emit
(
'success'
,
results
)
this
.
emit
(
'success'
,
results
)
...
...
spec-jasmine/postgres/query-generator.spec.js
View file @
441ea3d
...
@@ -127,37 +127,37 @@ describe('QueryGenerator', function() {
...
@@ -127,37 +127,37 @@ describe('QueryGenerator', function() {
updateQuery
:
[
updateQuery
:
[
{
{
arguments
:
[
'myTable'
,
{
name
:
'foo'
,
birthday
:
new
Date
(
Date
.
UTC
(
2011
,
2
,
27
,
10
,
1
,
55
))},
{
id
:
2
}],
arguments
:
[
'myTable'
,
{
name
:
'foo'
,
birthday
:
new
Date
(
Date
.
UTC
(
2011
,
2
,
27
,
10
,
1
,
55
))},
{
id
:
2
}],
expectation
:
"UPDATE \"myTable\" SET \"name\"='foo',\"birthday\"='2011-03-27 10:01:55.0' WHERE \"id\"=2"
expectation
:
"UPDATE \"myTable\" SET \"name\"='foo',\"birthday\"='2011-03-27 10:01:55.0' WHERE \"id\"=2
RETURNING *
"
},
{
},
{
arguments
:
[
'myTable'
,
{
name
:
'foo'
,
birthday
:
new
Date
(
Date
.
UTC
(
2011
,
2
,
27
,
10
,
1
,
55
))},
2
],
arguments
:
[
'myTable'
,
{
name
:
'foo'
,
birthday
:
new
Date
(
Date
.
UTC
(
2011
,
2
,
27
,
10
,
1
,
55
))},
2
],
expectation
:
"UPDATE \"myTable\" SET \"name\"='foo',\"birthday\"='2011-03-27 10:01:55.0' WHERE \"id\"=2"
expectation
:
"UPDATE \"myTable\" SET \"name\"='foo',\"birthday\"='2011-03-27 10:01:55.0' WHERE \"id\"=2
RETURNING *
"
},
{
},
{
arguments
:
[
'myTable'
,
{
bar
:
2
},
{
name
:
'foo'
}],
arguments
:
[
'myTable'
,
{
bar
:
2
},
{
name
:
'foo'
}],
expectation
:
"UPDATE \"myTable\" SET \"bar\"=2 WHERE \"name\"='foo'"
expectation
:
"UPDATE \"myTable\" SET \"bar\"=2 WHERE \"name\"='foo'
RETURNING *
"
},
{
},
{
arguments
:
[
'myTable'
,
{
name
:
"foo';DROP TABLE myTable;"
},
{
name
:
'foo'
}],
arguments
:
[
'myTable'
,
{
name
:
"foo';DROP TABLE myTable;"
},
{
name
:
'foo'
}],
expectation
:
"UPDATE \"myTable\" SET \"name\"='foo'';DROP TABLE myTable;' WHERE \"name\"='foo'"
expectation
:
"UPDATE \"myTable\" SET \"name\"='foo'';DROP TABLE myTable;' WHERE \"name\"='foo'
RETURNING *
"
},
{
},
{
arguments
:
[
'myTable'
,
{
bar
:
2
,
nullValue
:
null
},
{
name
:
'foo'
}],
arguments
:
[
'myTable'
,
{
bar
:
2
,
nullValue
:
null
},
{
name
:
'foo'
}],
expectation
:
"UPDATE \"myTable\" SET \"bar\"=2,\"nullValue\"=NULL WHERE \"name\"='foo'"
expectation
:
"UPDATE \"myTable\" SET \"bar\"=2,\"nullValue\"=NULL WHERE \"name\"='foo'
RETURNING *
"
},
{
},
{
arguments
:
[
'myTable'
,
{
bar
:
2
,
nullValue
:
null
},
{
name
:
'foo'
}],
arguments
:
[
'myTable'
,
{
bar
:
2
,
nullValue
:
null
},
{
name
:
'foo'
}],
expectation
:
"UPDATE \"myTable\" SET \"bar\"=2,\"nullValue\"=NULL WHERE \"name\"='foo'"
,
expectation
:
"UPDATE \"myTable\" SET \"bar\"=2,\"nullValue\"=NULL WHERE \"name\"='foo'
RETURNING *
"
,
context
:
{
options
:
{
omitNull
:
false
}}
context
:
{
options
:
{
omitNull
:
false
}}
},
{
},
{
arguments
:
[
'myTable'
,
{
bar
:
2
,
nullValue
:
null
},
{
name
:
'foo'
}],
arguments
:
[
'myTable'
,
{
bar
:
2
,
nullValue
:
null
},
{
name
:
'foo'
}],
expectation
:
"UPDATE \"myTable\" SET \"bar\"=2 WHERE \"name\"='foo'"
,
expectation
:
"UPDATE \"myTable\" SET \"bar\"=2 WHERE \"name\"='foo'
RETURNING *
"
,
context
:
{
options
:
{
omitNull
:
true
}}
context
:
{
options
:
{
omitNull
:
true
}}
},
{
},
{
arguments
:
[
'myTable'
,
{
bar
:
2
,
nullValue
:
undefined
},
{
name
:
'foo'
}],
arguments
:
[
'myTable'
,
{
bar
:
2
,
nullValue
:
undefined
},
{
name
:
'foo'
}],
expectation
:
"UPDATE \"myTable\" SET \"bar\"=2 WHERE \"name\"='foo'"
,
expectation
:
"UPDATE \"myTable\" SET \"bar\"=2 WHERE \"name\"='foo'
RETURNING *
"
,
context
:
{
options
:
{
omitNull
:
true
}}
context
:
{
options
:
{
omitNull
:
true
}}
},
{
},
{
arguments
:
[
'mySchema.myTable'
,
{
name
:
'foo'
,
birthday
:
new
Date
(
Date
.
UTC
(
2011
,
2
,
27
,
10
,
1
,
55
))},
{
id
:
2
}],
arguments
:
[
'mySchema.myTable'
,
{
name
:
'foo'
,
birthday
:
new
Date
(
Date
.
UTC
(
2011
,
2
,
27
,
10
,
1
,
55
))},
{
id
:
2
}],
expectation
:
"UPDATE \"mySchema\".\"myTable\" SET \"name\"='foo',\"birthday\"='2011-03-27 10:01:55.0' WHERE \"id\"=2"
expectation
:
"UPDATE \"mySchema\".\"myTable\" SET \"name\"='foo',\"birthday\"='2011-03-27 10:01:55.0' WHERE \"id\"=2
RETURNING *
"
},
{
},
{
arguments
:
[
'mySchema.myTable'
,
{
name
:
"foo';DROP TABLE mySchema.myTable;"
},
{
name
:
'foo'
}],
arguments
:
[
'mySchema.myTable'
,
{
name
:
"foo';DROP TABLE mySchema.myTable;"
},
{
name
:
'foo'
}],
expectation
:
"UPDATE \"mySchema\".\"myTable\" SET \"name\"='foo'';DROP TABLE mySchema.myTable;' WHERE \"name\"='foo'"
expectation
:
"UPDATE \"mySchema\".\"myTable\" SET \"name\"='foo'';DROP TABLE mySchema.myTable;' WHERE \"name\"='foo'
RETURNING *
"
}
}
],
],
...
...
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