A dyno client which extends the aws-sdk's DocumentClient.
Break a large batch of get operations into a set of requests that are intended to be sent concurrently.
Parameters
params
object unbounded batchGetItem request parameters. See DocumentClient.batchGet for details.
Returns CompleteRequestSet
Perform a batch of get operations. Passthrough to DocumentClient.batchGet.
Parameters
params
object request parameters. See DocumentClient.batchGet for details.callback
[function] a function to handle the response. See DocumentClient.batchGet for details.
Returns Request
Break a large batch of get operations into a set of requests that can be sent individually or concurrently.
Parameters
params
object unbounded batchGetItem request parameters. See DocumentClient.batchGet for details.
Returns RequestSet
Break a large batch of write operations into a set of requests that are intended to be sent concurrently.
Parameters
params
object unbounded batchWriteItem request parameters. See DocumentClient.batchWrite for details.
Returns CompleteRequestSet
Perform a batch of write operations. Passthrough to DocumentClient.batchWrite.
Parameters
params
object request parameters. See DocumentClient.batchWrite for details.callback
[function] a function to handle the response. See DocumentClient.batchWrite for details.
Returns Request
Break a large batch of write operations into a set of requests that can be sent individually or concurrently.
Parameters
params
object unbounded batchWriteItem request parameters. See DocumentClient.batchWrite for details.
Returns RequestSet
Create a table. Passthrough to DynamoDB.createTable, except the function polls DynamoDB until the table is ready to accept reads and writes, at which point the callback function is called.
Parameters
params
object request parameters. See DynamoDB.createTable for details.callback
[function] a function to handle the response. See DynamoDB.createTable for details.
Returns Request
Delete a single record. Passthrough to DocumentClient.delete.
Parameters
params
object request parameters. See DocumentClient.delete for details.callback
[function] a function to handle the response. See DocumentClient.delete for details.
Returns Request
Delete a table. Passthrough to DynamoDB.deleteTable, except the function polls DynamoDB until the table is ready to accept reads and writes, at which point the callback function is called.
Parameters
params
object request parameters. See DynamoDB.deleteTable for details.callback
[function] a function to handle the response. See DynamoDB.deleteTable for details.
Returns Request
Get table information. Passthrough to DynamoDB.describeTable.
Parameters
params
object request parameters. See DynamoDB.describeTable for details.callback
[function] a function to handle the response. See DynamoDB.describeTable for details.
Returns Request
Get a single record. Passthrough to DocumentClient.get.
Parameters
params
object request parameters. See DocumentClient.get for details.callback
[function] a function to handle the response. See DocumentClient.get for details.
Returns Request
List the tables available in a given region. Passthrough to DynamoDB.listTables.
Parameters
params
object request parameters. See DynamoDB.listTables for details.callback
[function] a function to handle the response. See DynamoDB.listTables for details.
Returns Request
Put a single record. Passthrough to DocumentClient.put.
Parameters
params
object request parameters. See DocumentClient.put for details.callback
[function] a function to handle the response. See DocumentClient.put for details.
Returns Request
Query a table or secondary index. Passthrough to DocumentClient.query.
Parameters
params
object request parameters. See DocumentClient.query for details.params.Pages
[number] maximum number of pages of query results to request. Set toInfinity
to return all available data. (optional, default1
)
callback
[function] a function to handle the response. See DocumentClient.query for details.
Returns **** a Request if not paginating, or a ReadableStream if multiple pages were requested
Provide the results of a query as a Readable Stream. This function will paginate through query responses, making HTTP requests as the caller reads from the stream.
Parameters
params
object query request parameters. See DocumentClient.query for details.
Returns ReadableStream
Scan a table or secondary index. Passthrough to DocumentClient.scan.
Parameters
params
object request parameters. See DocumentClient.scan for details.params.Pages
[number] maximum number of pages of scan results to request. Set toInfinity
to return all available data. (optional, default1
)
callback
[function] a function to handle the response. See DocumentClient.scan for details.
Returns **** a Request if not paginating, or a ReadableStream if multiple pages were requested
Provide the results of a scan as a Readable Stream. This function will paginate through query responses, making HTTP requests as the caller reads from the stream.
Parameters
params
object scan request parameters. See DocumentClient.scan for details.
Returns ReadableStream
Update a single record. Passthrough to DocumentClient.update.
Parameters
params
object request parameters. See DocumentClient.update for details.callback
[function] a function to handle the response. See DocumentClient.update for details.
Returns Request
An array of AWS.Requests
Send all the requests in a set, optionally specifying concurrency. This function will retry unprocessed items and return a single response body aggregated from results of all the individual requests.
The callback function will be passed a single error object if any occurred, and the aggregated response body. If all requests encountered an error, the second argument will be null. Otherwise the callback may be provided with an error as well as the outcome from successful requests.
Parameters
concurrency
[number] the concurrency with which to make requests. Default value is1
.callback
function a function to handle the response.
Creates a dyno client. You must provide a table name and the region where the table resides. Where applicable, dyno will use this table as the default in your requests. However you can override this when constructing any individual request.
If you do not explicitly pass credentials when creating a dyno client, the aws-sdk will look for credentials in a variety of places. See the configuration guide for details.
Parameters
options
object configuration parametersoptions.table
string the name of the table to interact with by defaultoptions.region
string the region in which the default table residesoptions.endpoint
[string] the dynamodb endpoint urloptions.httpOptions
[object] httpOptions to provide the aws-sdk client. See constructor docs for details.options.accessKeyId
[string] credentials for the client to utilizeoptions.secretAccessKey
[string] credentials for the client to utilizeoptions.sessionToken
[string] credentials for the client to utilizeoptions.logger
[object] a writable stream for detailed logging from the aws-sdk. See constructor docs for details.options.maxRetries
[number] number of times to retry on retryable errors. See constructor docs for details.
Examples
var Dyno = require('dyno');
var dyno = Dyno({
table: 'my-table',
region: 'us-east-1'
});
Returns client a dyno client
Create a DynamoDB set. When writing records to DynamoDB, arrays are interpretted
as List
type attributes. Use this function to utilize a Set
instead.
Parameters
list
array an array of strings, numbers, or buffers to store in DynamoDB as a set
Examples
// This record will store the `data` attribute as a `List` in DynamoDB
var asList = {
id: 'my-record',
data: [1, 2, 3]
};
// This record will store the `data` attribute as a `NumberSet` in DynamoDB
var asNumberSet = {
id: 'my-record',
data: Dyno.createSet([1, 2, 3]);
};
Returns object a DynamoDB set
Convert a wire-formatted string into a JavaScript object
Parameters
str
string the serialized representation of a DynamoDB record
Examples
var str = '{"id":{"S":"my-record"},"version":{"N":"2"},"data":{"B":"SGVsbG8gV29ybGQh"}}';
console.log(Dyno.deserialize(str));
// {
// id: 'my-record',
// version: 2,
// data: <Buffer 48 65 6c 6c 6f 20 57 6f 72 6c 64 21>
// }
Returns object a JavaScript object representing the record
Provides a dyno client capable of reading from one table and writing to another.
Parameters
readOptions
object configuration parameters for the read table.writeOptions
object configuration parameters for the write table.
Returns dyno a dyno client.
Convert a JavaScript object into a wire-formatted string that can be sent to DynamoDB in an HTTP request.
Parameters
item
object a JavaScript object representing a DynamoDB record
Examples
var item = {
id: 'my-record',
version: 2,
data: new Buffer('Hello World!')
};
console.log(Dyno.serialize(item));
// {"id":{"S":"my-record"},"version":{"N":"2"},"data":{"B":"SGVsbG8gV29ybGQh"}}
Returns string the serialized representation of the record
Creates a Writable stream.
Writing individual records to the stream will aggregate them into sets of
25 items and submit them as BatchWriteItem
requests.
Parameters
options
object stream options. See Writable stream documentation for available options. The stream will always setobjectMode: true
for you.options.concurrency
[number] set the maximum desired concurrency for outgoing BatchWriteItem requests. (optional, default1
)options.retry
[function] sets the provided function as a retry event listener on outgoing BatchWriteItem requests.
Returns **** a Writable stream
A Node.js Readable Stream. See node.js documentation for details.
This is an objectMode = true
stream, where each object emitted is a single
DynamoDB record.
Properties
ConsumedCapacity
object once the stream has begun making requests, theConsumedCapacity
parameter will report the total capacity consumed by the aggregate of all requests that have completed. This property will only be present if theReturnConsumedCapacity
parameter was set on the initial request.
Reduce two sets of consumed capacity metrics into a single object
Parameters
existing
object capacity. This object will be updated.new
object capacity object to be added to the existing object.incoming
An object representing an aws-sdk request. See aws-sdk's documentation for details
An array of AWS.Requests
Send all the requests in a set, optionally specifying concurrency. The emphasis is on making it transparent to the caller the exact outcome of each request in the set.
The callback function will be passed arguments in this order:
- error: set to null if no errors occurred, otherwise an array of errors with indexes that correspond to the indexes of the original request set
- responses: always an array of responses equal with indexes corresponding
to the original request set. If a particular request encountered an error,
that index in the
responses
array will be set tonull
. - unprocessed: set to null if no unprocessed results were detected, otherwise a new set of requests with its own .sendAll function bound to it. Again, indexes correspond to those in the original request set.
Parameters
concurrency
[number] the concurrency with which to make requests. Default value is1
.callback
function a function to handle the response.