不要怂,就是干,撸起袖子干!

Commit 2481b8d1 by Jan Aagaard Meier

postgres and sqlite increment

1 parent 9d1b8f6f
......@@ -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') {
......
......@@ -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.
......
......@@ -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 = {}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!