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