aws-simple-iterator
v1.1.0
Published
Simple AWS Iterator functions
Downloads
12
Readme
aws-simple-iterator
Simple AWS Iterator functions
Install
npm install aws-simple-iterator
API Reference
Simple AWS Iterator functions
Example
import { getAll, paginate, items } from 'aws-simple-iterator'
import { DynamoDB } from '@aws-sdk/client-dynamodb'
const tableName = 'myTable'
const ddb = new DynamoDB({ region: 'eu-west-1' })
const iterable = {
parameters: { TableName: tableName },
func: ddb.scan.bind(ddb), // Note: `bind` the function to the client
dataKey: 'Items',
returnedNextToken: 'LastEvaluatedKey',
paramNextToken: 'ExclusiveStartKey',
}
// get all the records using the getAll function
const all = await getAll(iterable)
// get all the records using the paginate function
const perPage = []
for await (const page of paginate(iterable)) {
perPage.push(...page)
}
// get all records using the 'items' function
const perItem = []
for await (const item of items(iterable)) {
perItem.push(item)
}
aws-simple-iterator.getAll ⇒ Promise.<Array>
Get all the results and return as an array
Kind: static constant of aws-simple-iterator
| Param | Type | | ----- | ----------------------- | | args | iterParams |
aws-simple-iterator.paginate(args) ⇒ AsyncGenerator
Paginate through results and yield each page
Kind: static method of aws-simple-iterator
| Param | Type | | ----- | ----------------------- | | args | iterParams |
aws-simple-iterator.items(args) ⇒ AsyncGenerator
Iterate one record at a time and yield each one
Kind: static method of aws-simple-iterator
| Param | Type | | ----- | ----------------------- | | args | iterParams |
aws-simple-iterator~iterParams : object
Kind: inner typedef of aws-simple-iterator
| Param | Type | Description | | ----------------- | --------------------- | ---------------------------------------------------- | | params | Object | The parameters to pass to the function | | func | function | The function to call | | dataKey | string | The key in the response that contains the data | | returnedNextToken | string | The key in the response that contains the next token | | paramNextToken | string | The key in the parameters to set the next token |