Fuse Datastore (fuse-datastore)
The fuse-datastore package contains all modules required to interact with DynamoDB on Fuse Platform.
Table of Contents
Features
- Get a multi-tenant safe instance of DynamoDB
- Cache the recently used connection
- Client code to connect to datastore
Installing
Using npm:
npm install @appfire/fuse-datastore
Once the package is installed, you can import the library using import
:
import {
FuseDynamoDBClientFactory,
FuseDynamoInstance,
} from '@appfire/fuse-datastore';
Example
Get Instance of DynamoDB Client
The API will return an instance of DynamoDB Client which safe for multiple tenants. You will need to provide tenantId in the constructor. Library will make sure that Lambda only have access to the records of specified tenant. It will also have improved performance by caching the connection. Note access of the instance expires in 15 minutes. If you need cache optimized version then use below example.
const ddFactory = FuseDynamoInstance.getInstance();
const ddb = await ddFactory.getClient(tenantId);
You can directly use ddb (DynamoDB client AWS SDK v3)
Get Instance of DynamoDB Client Cache Optimized
The API will return an instance of DynamoDB Client which safe for multiple tenants. You will need to provide tenantId in the constructor. Library will make sure that Lambda only have access to the records of specified tenant. It will also have improved performance by caching the connection. The connection is created for 15 minutes. The cache optimized version will automatically request a new instance when cache expires.
const ddFactory = FuseDynamoInstance.getInstanceCacheOptimised();
const ddb = await ddFactory.getClient(tenantId);
You can directly use ddb (DynamoDB client AWS SDK v3)
Work with Dynamoose
Dynamoose is a popular ORM library for DynamoDB. You can read more about it here. (https://dynamoosejs.com/getting_started/Introduction) You can use above ddb object to set as the interaction layer for dynamodb in Dynamoose
dynamoose.aws.ddb.set(ddb);