@travetto/model-dynamodb
v5.0.17
Published
DynamoDB backing for the travetto model module.
Downloads
180
Maintainers
Readme
DynamoDB Model Support
DynamoDB backing for the travetto model module.
Install: @travetto/model-dynamodb
npm install @travetto/model-dynamodb
# or
yarn add @travetto/model-dynamodb
This module provides an DynamoDB-based implementation for the Data Modeling Support. This source allows the Data Modeling Support module to read, write and query against DynamoDB. The entire document is stored as a single value, so nothing is needed to handle schema updates in real time. Indices on the other hand are more complicated, and will not be retroactively computed for new values.
Supported features:
- CRUD
- Expiry
- Indexed Out of the box, by installing the module, everything should be wired up by default.If you need to customize any aspect of the source or config, you can override and register it with the Dependency Injection module.
Code: Wiring up a custom Model Source
import { InjectableFactory } from '@travetto/di';
import { DynamoDBModelService, DynamoDBModelConfig } from '@travetto/model-dynamodb';
export class Init {
@InjectableFactory({ primary: true })
static getModelService(conf: DynamoDBModelConfig) {
return new DynamoDBModelService(conf);
}
}
where the DynamoDBModelConfig is defined by:
Code: Structure of DynamoDBModelConfig
import type dynamodb from '@aws-sdk/client-dynamodb';
import { Config } from '@travetto/config';
import { Field } from '@travetto/schema';
@Config('model.dynamodb')
export class DynamoDBModelConfig {
@Field(Object)
client: dynamodb.DynamoDBClientConfig = {
endpoint: undefined
};
autoCreate?: boolean;
namespace?: string;
}
Additionally, you can see that the class is registered with the @Config annotation, and so these values can be overridden using the standard Configuration resolution paths.