-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbatch.js
56 lines (43 loc) · 967 Bytes
/
batch.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
function Batch(tableName) {
this.tableName = tableName;
this.putRequests = [];
}
Batch.prototype.addRow = function(row) {
var item = {};
// See http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB.html#batchWriteItem-property
// Example "Item" JSON:
//
// "Item": {
// "column1": {
// "S": "foo"
// },
// "column2": {
// "S": "bar"
// }
// }
// Right now, we only support string values.
for (var column in row) {
var value = row[column];
if (value && value.length > 0) {
item[column] = { "S": value };
}
}
var request = {
"PutRequest": {
"Item": item
}
};
this.putRequests.push(request);
}
Batch.prototype.getLength = function() {
return this.putRequests.length;
}
Batch.prototype.getBatchWriteItemParams = function() {
var tableRequests = {};
tableRequests[this.tableName] = this.putRequests;
var params = {
"RequestItems": tableRequests
};
return params;
}
module.exports = Batch;