dynamo-table-id
Adds a nextId
function to a dynamo-table instance to
generate incrementing numbers using DynamoDB's ADD
command in the
UpdateItem
action
Example
var dynamoTable = dynamoTableId = // Will use us-east-1 and credentials from process.env unless otherwise specifiedvar table = table = // By default the first value will be 1table // Will return a collection of values if a length is providedtable // Can also set a value to start incrementing fromtable
API
dynamoTableId(table, [options])
Wraps the given dynamo-table object with the methods given below.
Current options are:
idTable
(defaults tolast-ids
) - the name of a table that must already exist with a string hash keykey
(defaults to the table name) - the hash key value used to hold the value itemattr
(defaults tolastId
) - the attribute name of the incrementing value
nextId([length], callback)
If length
is not specified, this will generate a new numerical value and return it in the callback -
otherwise an array of numbers of the given length is generated and returned (even if length is 0 or 1).
setLastId(lastId, callback)
Sets the current value of the last value - ie, the next generated value will be an increment above this value.
Installation
With npm do:
npm install dynamo-table-id