dynapromise-full-query
v0.0.2
Published
A full DynamoDB query in a promise.
Downloads
3
Readme
dynapromise-full-query
A full query of a DynamoDB table in a promise; it fetches all items matching the query, not just the first batch returned by AWS.
Install
npm install dynapromise-full-query
or
yarn add dynapromise-full-query
Usage
Async/await syntax
import fullQuery from 'dynapromise-full-query'
const countAllItems = async () => {
try {
const items = await fullQuery(
{ ... }, // Options used in 'new AWS.DynamoDB(options = {})' (see notes),
{ ... }, // Options used in 'dynamodb.query(options = {})' (see notes),
{
// Whether or not to surpress returning the results
noReturn: false,
// Function to process chunks of items as they are returned from AWS
onChunk: () => {},
// Number of times to reattempt retryable errors. Default 50.
errorRetries: 50,
}
)
console.log(`Query returned ${items.length} item/s`)
}
catch (err) {
console.error(err)
}
}
Promise syntax
const fullQuery = require('dynapromise-full-query');
const countAllItems = fullQuery(
{ ... }, // Options used in 'new AWS.DynamoDB(options = {})' (see notes),
{ ... }, // Options used in 'dynamodb.query(options = {})' (see notes),
{
// Whether or not to surpress returning the results
noReturn: false,
// Function to process chunks of items as they are returned from AWS
onChunk: () => {},
// Number of times to reattempt retryable errors. Default 50.
errorRetries: 50,
}
)
.then(items => console.log(`Query returned ${items.length} item/s`))
.catch(err => console.error(err))
Error handling
Errors are not caught by fullQuery as how they are handled is application specific. Therefore, please use try...catch
syntax when using async
syntax or the .catch
method when using Promise
syntax.
API
fullQuery(dbOptions, queryParams, [fullQueryParams])
Performs a dynamodb query using the given db connection information and query options.
dbOptions
- an object passed to the AWS.DynamoDB constructor (see notes)queryParams
- an object passed to the AWS.DynamoDB.query method (see notes)fullQueryParams
- an object with options for the fullQuery callnoReturn
- a boolean value indicating if results should be returned or not.onChunk
- a function which is processed for each chunk of items returned. Receives the same data object defined in the AWS.DynamoDB.query callback method (see notes).errorRetries
- a int value stating the number of times to retry retriable errors before throwing the error. Default 50.