This package aims to provide a “humanized" and more readable support of DynamoDB DocumentClient.
$ npm install dynamo-record --save
OR
$ yarn add dynamo-record
// assumes AWS.config is set up already
import { DynamoRecord } from "dynamo-record";
const repo = new DynamoRecord<DataType, WhereType>(tableName, config, tracing);
-
tableName
string the table name -
config
Dynamo Client Configuration The AWS DynamoDB configuration object -
tracing
optional - boolean enable or disable AWS X-Ray tracing feature. Default is false.
The library generates the DynamoDB config for you.
In some cases where a method will not allow you to accomplish what you would like, each method has an optional params config
where you can override each DocumentClient basic params. API documentation specify which basic method from DocumentClient is extended.
In Dynamo Record, all params for config
are camelize (fooBar) key instead of pascalize (FooBar).
The following methods are available. All DocumentClient methods are not already implemented
Return a single element based on his primary key
repo.find(primaryKey, config);
Extend: get()
-
primaryKey
object with hash and range key. Provided keys must match dynamoDB schema. -
config
optional - object with DocumentClient params.
Return all items that match primary key and/or condition
repo.where(primaryKey, filterExpression, config);
-
primaryKey
optional - object with hash and range key. Provided keys must match dynamoDB schema. -
filterExpression
optional - object with required condition and keys property. -
config
optional - object with DocumentClient params.
Return all items
repo.getAll(config);
Extend: scan()
-
config
optional - object with DocumentClient params.
Add a new item
repo.create(createData, config);
Extend: put()
-
createData
object with data to add into table. -
config
optional - object with DocumentClient params.
Add an array of items
repo.batchCreate(createData, config);
Extend: batchWrite()
-
createData
array of items to add into table. -
config
optional - object with DocumentClient params.
Update an item based on his primary key
repo.update(primaryKey, updateData, config);
Extend: update()
-
primaryKey
object with hash and range key. Provided keys must match dynamoDB schema. -
updateData
object with item data to update. -
config
optional - object with DocumentClient params.
Only update object endpoint values based on his primary key
The updated object must have a full existing tree of all nested object before the update. DynamoDB can't update a property and create it's parent object on the same request.
If user wants to update a whole object without knowing the nested content, he can pass a custom config through updateExpression, expressionAttributeNames and expressionAttributeValues.
repo.deepUpdate(primaryKey, updateData, config);
Extend: update()
-
primaryKey
object with hash and range key. Provided keys must match dynamoDB schema. -
updateData
object with item data to update. -
config
optional - object with DocumentClient params.
Remove an item
repo.delete(primaryKey, config);
Extend: delete()
-
primaryKey
object with hash and range key. Provided keys must match dynamoDB schema. -
config
optional - object with DocumentClient params.