Simple AWS DynamoDB driver for nodejs
Simple Node.js DynamoDB driver to perform basic CRUD operations, it is meant to be as simple as possible.
Installation
npm i dynamodb-driver
Initialisation
var DDbDriver = table = ;
Example
var table = ;
Create row
Creates a row in the specified table, and id will be automatically generated using shorId if non exists in the document Returns a promise resolving a document that has just been created
Usage
somePromise = table;
Example
table;
Update row
Usage
somePromise = table;
conditions: An object with a ConditionExpression and a ExpressionAttributeValues (See: http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_UpdateItem.html)
keys: Should you table is not using id as primary key, you can specify your primary and sort key here such as ["organisationId", "documentId"]
Conditional write
Specify a value within brackets with a exclamation mark to perform an update only if the value doesn't exist
id: "S1KtimR6" creationDate: "[!" + + "]"
Increment
Specify a value within brackets with ++ to perform an increment by one of the existing value
id: "S1KtimR6" count: "[++]"
Decrement
Specify a value within brackets with -- to perform an decrement by one of the existing value
id: "S1KtimR6" count: "[--]"
Example
table;
Query rows
Usage
somePromise = table;
query:
- could be an array for the query with the key, ComparisonOperator and AttributeValueList for legacy KeyConditions.
- could be an object with a KeyConditionExpression and ExpressionAttributeNames
Example
// Using the legacy KeyConditions mode table;
Get row by Key
Usage
somePromise = table;
Example
table;
Get multiple rows by Key
Usage
somePromise = table;
arrayOfIds: An array of ids to retrieve or an array of objects containing the partition and sort key of the items to retrieve
options: is an optional object
options.consistentRead: true or false, will apply strongly consistent reads instead of the default setting (eventually consistent reads)
options.keys: an array of 1 or 2 strings defining the partition and sort keys
Example
table;
Delete row
Usage
somePromise = table;
Example
table;
Delete multiple rows by Key
Usage
somePromise = table;
keys: when not using id as a primary, you must specify the HASH and optionally RANGE key
Example
table;
List rows
Usage
somePromise = table;
Will perform a scan operation on the selected table
query: A specific query array to filter data against options: An object with a paginate property as number. It will recursively fetch batches of paginate value until all data is fetched for this query (note, no exponential backing off)
Example
table;