Created
April 25, 2017 03:31
-
-
Save longsangstan/8874a008cb4fa90322d9c8c4545303e0 to your computer and use it in GitHub Desktop.
dynamodb scan 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 docClient = require("../aws").docClient; | |
var co = require("co"); | |
var scanAll = co.wrap(function*( | |
tableName, | |
previousItems, | |
lastEvaluatedKey | |
) { | |
var items = previousItems || []; | |
var params = { | |
TableName: tableName | |
}; | |
if (lastEvaluatedKey) { | |
params["ExclusiveStartKey"] = lastEvaluatedKey; | |
} | |
var scanResult = yield docClient.scan(params).promise(); | |
items = items.concat(scanResult.Items); | |
if (typeof scanResult.LastEvaluatedKey != "undefined") { | |
console.log("SCAN FOR MORE"); | |
return yield scanAll(tableName, items, scanResult.LastEvaluatedKey); | |
} else { | |
console.log("OK - NUM OF ITEMS:" + items.length); | |
return yield Promise.resolve(items); | |
} | |
}); | |
module.exports = scanAll; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment