- Dyno
- client
- Request
- ReadableStream
- RequestSet
- CompleteRequestSet
- putStream
- reduceCapacity
- castIndexesCapacity
- callCostLogger
- requestHandler
- getMethodType
- wrapDocClient
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.
-
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.options.costLogger
function? a function that will be called with consumedCapacityoptions.dynoInstance
Dyno? a Dyno instance that will share the underlying AWS client with this one
var Dyno = require('dyno');
var dyno = Dyno({
table: 'my-table',
region: 'us-east-1'
});
Returns client a dyno client
Provides a dyno client capable of reading from one table and writing to another.
readOptions
object configuration parameters for the read table.writeOptions
object configuration parameters for the write table.
Returns dyno 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.
list
array an array of strings, numbers, or buffers to store in DynamoDB as a set
// 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 JavaScript object into a wire-formatted string that can be sent to DynamoDB in an HTTP request.
item
object a JavaScript object representing a DynamoDB record
var item = {
id: 'my-record',
version: 2,
data: new Buffer.from('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
Convert a wire-formatted string into a JavaScript object
str
string the serialized representation of a DynamoDB record
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
A dyno client which extends the aws-sdk's DocumentClient.
List the tables available in a given region. Passthrough to DynamoDB.listTables.
params
object request parameters. See DynamoDB.listTables for details.callback
function? a function to handle the response. See DynamoDB.listTables for details.
Returns Request
Get table information. Passthrough to DynamoDB.describeTable.
params
object request parameters. See DynamoDB.describeTable for details.callback
function? a function to handle the response. See DynamoDB.describeTable for details.
Returns Request
Perform a batch of get operations. Passthrough to DocumentClient.batchGet.
params
object request parameters. See DocumentClient.batchGet for details.callback
function? a function to handle the response. See DocumentClient.batchGet for details.
Returns Request
Perform a batch of write operations. Passthrough to DocumentClient.batchWrite.
params
object request parameters. See DocumentClient.batchWrite for details.callback
function? a function to handle the response. See DocumentClient.batchWrite for details.
Returns Request
Delete a single record. Passthrough to DocumentClient.delete.
params
object request parameters. See DocumentClient.delete for details.callback
function? a function to handle the response. See DocumentClient.delete for details.
Returns Request
Get a single record. Passthrough to DocumentClient.get.
params
object request parameters. See DocumentClient.get for details.callback
function? a function to handle the response. See DocumentClient.get for details.
Returns Request
Put a single record. Passthrough to DocumentClient.put.
params
object request parameters. See DocumentClient.put for details.callback
function? a function to handle the response. See DocumentClient.put for details.
Returns Request
Update a single record. Passthrough to DocumentClient.update.
params
object request parameters. See DocumentClient.update for details.callback
function? a function to handle the response. See DocumentClient.update for details.
Returns Request
Break a large batch of get operations into a set of requests that can be sent individually or concurrently.
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 can be sent individually or concurrently.
params
object unbounded batchWriteItem request parameters. See DocumentClient.batchWrite for details.
Returns RequestSet
Break a large batch of get operations into a set of requests that are intended to be sent concurrently.
params
object unbounded batchGetItem request parameters. See DocumentClient.batchGet for details.
Returns CompleteRequestSet
Break a large batch of write operations into a set of requests that are intended to be sent concurrently.
params
object unbounded batchWriteItem request parameters. See DocumentClient.batchWrite for details.
Returns CompleteRequestSet
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.
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 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.
params
object request parameters. See DynamoDB.deleteTable for details.callback
function? a function to handle the response. See DynamoDB.deleteTable for details.
Returns Request
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.
params
object query request parameters. See DocumentClient.query for details.
Returns ReadableStream
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.
params
object scan request parameters. See DocumentClient.scan for details.
Returns ReadableStream
Query a table or secondary index. Passthrough to DocumentClient.query.
-
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 any a Request if not paginating, or a ReadableStream if multiple pages were requested
Scan a table or secondary index. Passthrough to DocumentClient.scan.
-
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 any a Request if not paginating, or a ReadableStream if multiple pages were requested
An object representing an aws-sdk request. See aws-sdk's documentation for details
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.
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.
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.
concurrency
number? the concurrency with which to make requests. Default value is1
.callback
function a function to handle the response.
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.
concurrency
number? the concurrency with which to make requests. Default value is1
.callback
function a function to handle the response.
Creates a Writable stream.
Writing individual records to the stream will aggregate them into sets of
25 items and submit them as BatchWriteItem
requests.
-
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 any a Writable stream
Reduce two sets of consumed capacity metrics into a single object This should be in sync with Callback Parameters section of https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/DocumentClient.html#query-property
existing
object capacity. This object will be updated.incoming
new
(object | array) capacity object(s) to be added to the existing object.
Cast CapacityUnits to ReadCapacityUnits or WriteCapacityUnits based on the cast type
indexes
Object GlobalSecondaryIndexes or LocalSecondaryIndexes see https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_ConsumedCapacity.html#DDB-Type-ConsumedCapacity-GlobalSecondaryIndexescastKey
string ReadCapacityUnits | WriteCapacityUnits
Call the costLogger function configured in the options with consumed CapacityUnits
res
object The response of dynamoDB requesttype
string Read | WritecostLogger
function configured in the optionsTime
number the time consumed
Wrap the native method of DynamoDB to call the costLogger in the callback. If no costLogger is provided, just return the native method directly
costLogger
function The function that will be called with casted consumedCapacitynativeMethod
function The native method of dynamoDBtype
string Indicate the method consumes Read or Write capacity
Get if a method is a write or read method
fnName
string
Returns any Write|Read
Wrap all methods used of DynamoDB DocumentClient with requestHandler