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 2481b8d1
authored
Jan 12, 2013
by
Jan Aagaard Meier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
postgres and sqlite increment
1 parent
9d1b8f6f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
55 additions
and
0 deletions
lib/dialects/postgres/query-generator.js
lib/dialects/query-generator.js
lib/dialects/sqlite/query-generator.js
lib/dialects/postgres/query-generator.js
View file @
2481b8d
...
...
@@ -357,6 +357,27 @@ module.exports = (function() {
return
Utils
.
_
.
template
(
query
)(
replacements
)
},
incrementQuery
:
function
(
tableName
,
attrValueHash
,
where
)
{
attrValueHash
=
Utils
.
removeNullValuesFromHash
(
attrValueHash
,
this
.
options
.
omitNull
)
var
query
=
"UPDATE <%= table %> SET <%= values %> WHERE <%= where %> RETURNING *"
,
values
=
[]
for
(
var
key
in
attrValueHash
)
{
var
value
=
attrValueHash
[
key
]
values
.
push
(
addQuotes
(
key
)
+
"="
+
addQuotes
(
key
)
+
pgEscape
(
value
))
}
var
replacements
=
{
table
:
addQuotes
(
tableName
),
values
:
values
.
join
(
","
),
where
:
QueryGenerator
.
getWhereConditions
(
where
)
}
return
Utils
.
_
.
template
(
query
)(
replacements
)
},
addIndexQuery
:
function
(
tableName
,
attributes
,
options
)
{
var
transformedAttributes
=
attributes
.
map
(
function
(
attribute
)
{
if
(
typeof
attribute
===
'string'
)
{
...
...
lib/dialects/query-generator.js
View file @
2481b8d
...
...
@@ -144,6 +144,20 @@ module.exports = (function() {
},
/*
Returns an update query.
Parameters:
- tableName -> Name of the table
- values -> A hash with attribute-value-pairs
- where -> A hash with conditions (e.g. {name: 'foo'})
OR an ID as integer
OR a string with conditions (e.g. 'name="foo"').
If you use a string, you have to escape it on your own.
*/
incrementQuery
:
function
(
tableName
,
values
,
where
)
{
throwMethodUndefined
(
'incrementQuery'
)
},
/*
Returns an add index query.
Parameters:
- tableName -> Name of an existing table.
...
...
lib/dialects/sqlite/query-generator.js
View file @
2481b8d
...
...
@@ -113,6 +113,26 @@ module.exports = (function() {
return
Utils
.
_
.
template
(
query
)(
replacements
)
},
incrementQuery
:
function
(
tableName
,
attrValueHash
,
where
)
{
attrValueHash
=
Utils
.
removeNullValuesFromHash
(
attrValueHash
,
this
.
options
.
omitNull
)
var
query
=
"UPDATE <%= table %> SET <%= values %> WHERE <%= where %>"
,
values
=
[]
for
(
var
key
in
attrValueHash
)
{
var
value
=
attrValueHash
[
key
]
values
.
push
(
Utils
.
addTicks
(
key
)
+
"="
+
Utils
.
addTicks
(
key
)
+
escape
((
value
instanceof
Date
)
?
Utils
.
toSqlDate
(
value
)
:
value
))
}
var
replacements
=
{
table
:
Utils
.
addTicks
(
tableName
),
values
:
values
.
join
(
","
),
where
:
MySqlQueryGenerator
.
getWhereConditions
(
where
)
}
return
Utils
.
_
.
template
(
query
)(
replacements
)
},
attributesToSQL
:
function
(
attributes
)
{
var
result
=
{}
...
...
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