@miermontoto/dynamo
v1.0.1
Published
Simple TypeScript wrapper for AWS DynamoDB operations
Downloads
30
Maintainers
Readme
@miermontoto/dynamo
Simple TypeScript wrapper for AWS DynamoDB operations with streamlined API and type safety.
Installation
pnpm add @miermontoto/dynamoConfiguration
interface DynamoWrapperConfig {
tableName: string;
partitionKey: string;
sortKey?: string;
region?: string; // defaults to AWS_REGION env or 'us-east-1'
credentials?: {
accessKeyId?: string;
secretAccessKey?: string;
};
clientOptions?: {
maxAttempts?: number; // default 3
connectionTimeout?: number; // default 5000ms
socketTimeout?: number; // default 60000ms
maxSockets?: number; // default 100
};
}Usage
import { DynamoWrapper } from '@miermontoto/dynamo';
// initialize client
const dynamo = new DynamoWrapper({
tableName: 'my-table',
partitionKey: 'userId',
sortKey: 'timestamp',
region: 'us-east-1',
credentials: {
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
},
});
// get item
const user = await dynamo.get('user-123', 1234567890);
// put item
await dynamo.put({
userId: 'user-123',
timestamp: Date.now(),
name: 'John Doe',
email: '[email protected]',
});
// query by partition key
const userItems = await dynamo.query('user-123', {
keyConditionExpression: 'timestamp > :start',
expressionValues: { ':start': 1234567000 },
limit: 10,
});
// update item
await dynamo.update('user-123', 1234567890, {
name: 'Jane Doe',
updatedAt: Date.now(),
});
// batch operations
const items = await dynamo.batchGet([
{ userId: 'user-123', timestamp: 1234567890 },
{ userId: 'user-456', timestamp: 1234567891 },
]);
// delete item
await dynamo.delete('user-123', 1234567890);License
CC BY-NC-ND 4.0
