This guide shows a minimal workflow to initialize an EntityClient, create a table, and perform simple CRUD.
Install
npm i @karmaniverous/entity-client-dynamodb
Wire an EntityClient
import {
EntityClient,
generateTableDefinition,
} from '@karmaniverous/entity-client-dynamodb';
import { EntityManager } from '@karmaniverous/entity-manager';
// Assume you have a value-first EntityManager; see "Type inference mental model"
declare const entityManager: EntityManager<any>;
const client = new EntityClient({
entityManager,
tableName: 'UserTable',
region: 'local',
// endpoint/credentials can be set for local development
});
Create the table from your EntityManager config
await client.createTable({
BillingMode: 'PAY_PER_REQUEST',
...generateTableDefinition(entityManager),
});
Put / Get
// Put a record (storage-facing shape)
await client.putItem({ hashKey2: 'h', rangeKey: 'r', a: 1 });
// Get a record (storage; token-aware)
const out = await client.getItem('user', { hashKey2: 'h', rangeKey: 'r' });
// Convert to domain (strip keys)
const item = out.Item && client.entityManager.removeKeys('user', out.Item);
Next steps