forked from goodybag/mongo-sql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.js
39 lines (31 loc) · 937 Bytes
/
update.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
* Update Behaviors
*/
var helpers = require('../lib/update-helpers');
var utils = require('../lib/utils');
/**
* Increment column
* Example:
* { $inc: { clicks: 1 } }
* @param {Object} Hash whose keys are the columns to inc and values are how much it will inc
*/
helpers.add('$inc', function(value, values, collection){
var output = "";
for (var key in value){
output += utils.quoteObject(key) + ' = ' + utils.quoteObject(key, collection) + ' + $' + values.push(value[key]);
}
return output;
});
/**
* Decrement column
* Example:
* { $dec: { clicks: 1 } }
* @param {Object} Hash whose keys are the columns to dec and values are how much it will inc
*/
helpers.add('$dec', function(value, values, collection){
var output = "";
for (var key in value){
output += utils.quoteObject(key) + ' = ' + utils.quoteObject(key, collection) + ' - $' + values.push(value[key]);
}
return output;
});