Created
April 28, 2017 09:16
-
-
Save longsangstan/7d03d737928f6e0106fb5a03ddd79130 to your computer and use it in GitHub Desktop.
dynamodb modify all items
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var scanAll = require("./scanAll"); | |
var docClient = require("../aws").docClient; | |
var co = require("co"); | |
var modifyAll = co.wrap(function*(table, action) { | |
var items = yield scanAll(table); | |
var promises = []; | |
for (var i = 0; i < items.length; i++) { | |
items[i] = action(items[i]); | |
var putShopParams = { | |
TableName: table, | |
Item: items[i] | |
}; | |
console.log('new item: ' + JSON.stringify(items[i])); | |
promises.push(docClient.put(putShopParams).promise()); | |
} | |
yield promises; | |
console.log("done"); | |
return yield Promise.resolve(); | |
}); | |
module.exports = modifyAll; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment