dynamodb-adapter
A library that implements the Write Model Adapter interface for storing events on dynamodb.
Here's an example of the table config in CloudFormation syntax:
1
EventStoreTable:
2
Type: 'AWS::DynamoDB::Table'
3
Properties:
4
TableName: someEntity ## <- your table name here
5
AttributeDefinitions:
6
- AttributeName: entityId
7
AttributeType: S
8
- AttributeName: version
9
AttributeType: N
10
- AttributeName: entityName
11
AttributeType: S
12
- AttributeName: commitId
13
AttributeType: S
14
KeySchema:
15
- AttributeName: entityId
16
KeyType: HASH
17
- AttributeName: version
18
KeyType: RANGE
19
GlobalSecondaryIndexes:
20
- IndexName: someEntityByCommitId ## <- your index name here
21
KeySchema:
22
- AttributeName: entityName
23
KeyType: HASH
24
- AttributeName: commitId
25
KeyType: RANGE
26
Projection:
27
ProjectionType: ALL
Copied!

Methods

build

build({ entityName }, { tableName, indexName, ...awsOptions )
builds a write model adapter

Parameters

attribute
type
description
entityName
string
the name of the entity
tableName
string
the name of the dynamodb table
indexName
string
the name of the index sorting commits by commitId
...awsOptions
object
any additional arguments are passed along to AWS, like so:new AWS.DynamoDB(awsOptions)

Returns

an object with write model methods

Example

adapter.js
1
const dynamoAdapterBuilder = require('serverless-cqrs.dynamodb-adapter')
2
module.exports = dynamoAdapterBuilder.build({
3
entityName: 'todo'
4
}, {
5
tableName: 'todos',
6
indexName: 'todosByCommitId',
7
region: 'eu-west-1',
8
})
Copied!
Last modified 2yr ago
Copy link