Typedorm
Strongly typed ORM for DynamoDB - Built with the single-table-design pattern in mind.
Install / Use
/learn @typedorm/TypedormREADME
TypeDORM
Object Relational mapper for DynamoDB, inspired by typeorm.
TypeDORM is an ORM built from the ground up using typescript and latest javascript features to provide an easy gateway when doing complex highly relational data modeling in DynamoDB. TypeDORM is built with single-table-design first in mind, but should work as smoothly with regular entity table <-> design pattern. TypeDORM would not have existed without TypeORM and dynamodb-toolbox, big shout-out to these projects and their awesome contributors.
TypeDORM borrows decorator based syntax from TypeORM and provides fully type safe ORM to work with dynamodb. TypeDORM currently only support Data Mapper.
Packages
| Package | Latest Stable | Recent Beta | Recent Alpha |
| ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
| @typedorm/common | |
|
|
| @typedorm/core |
|
|
|
| @typedorm/testing |
|
|
|
| @typedorm/document-client |
|
|
|
Branches
| Branches | Stability |
| -------- | ----------------------------------------------------------------------------------------- |
| main | |
| develop |
|
| alpha |
|
Features
- AWS SDK V2 and V3 unified support
- Single-Table design pattern first class support
- DataMapper development pattern
- Attribute level per entity transformation, enabled via class-transformer
- Full type safety
- Declarative relational schema
- Entity manager - easy to use
findOne,find,count,exists,create,update, anddeleteoperations - Transaction manager - easy to use
writeandreadoperations - Batch manager - powerful
writeandreadoperations - Scan Manager - powerful
find,count,parallelScanandscanoperations - Safer parallel scan with configurable concurrency control
- Multiple connections support
- Code follows all possible best practices when modeling for dynamodb
- Supports specifying non key attribute as unique, built in pagination support for querying
- Supports updating Primary key attributes
- Auto Generated values for attributes
- Auto update attribute values on UPDATE operations
- Most type safe, powerful and flexible update expression generator engine
- Dynamic & Static default values for attributes
- Complex update, key condition and condition expression all made easy to work with
- Powerful expression builder to auto generate expressions from input
- Typescript and javascript support
- Commonjs and ESM module support out of the box (see more here)
And many more to come.
Getting Started
Installation
-
Install core and common modules from npm.
npm install @typedorm/core @typedorm/common --save -
Install AWS SDK for nodejs, TypeDORM uses documentClient to interact with dynamodb. a. When using AWS SDK Version 2
npm install aws-sdk --saveb. When using AWS SDK Version 3
npm install @aws-sdk/client-dynamodb @aws-sdk/lib-dynamodb --save -
Install
reflect-metadatashimnpm install reflect-metadata --saveand import it as the first thing in node entry file as
import 'reflect-metadata'
Typescript configuration
If you are using TypeDORM with typescript, make sure you also have below options enabled in tsconfig.json
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
Developing with TypeDORM
Creating Table
First thing to do when working with TypeDORM is to setup dynamodb table config. Currently this needs to be manually setup and have it configured in deployed table instance(s).
This guide shows how to setup single-table-design
my-table.ts
import {Table, INDEX_TYPE} from '@typedorm/common';
// create table
const myGlobalTable = new Table({
name: 'test-table',
partitionKey: 'PK',
sortKey: 'SK',
indexes: {
GSI1: {
type: INDEX_TYPE.GSI,
partitionKey: 'GSI1PK',
sortKey: 'GSI1SK',
},
GSI2: {
type: INDEX_TYPE.GSI,
partitionKey: 'GSI2PK',
sortKey: 'GSI2SK',
},
LSI1: {
type: INDEX_TYPE.LSI,
sortKey: 'LSI1SK',
},
},
});
Note: These indexes must match exactly to what is created in dynamo table instance hosted.
Creating an entity
organisation.entity.ts
import {Attribute, Entity, AutoGenerateAttribute} from '@typedorm/common';
import {AUTO_GENERATE_ATTRIBUTE_STRATEGY} from '@typedorm/common';
@Entity({
name: 'organisation',
primaryKey: {
partitionKey: 'ORG#{{id}}',
sortKey: 'ORG#{{id}}',
},
indexes: {
// specify GSI1 key - "GSI1" named global secondary index needs to exist in above table declaration
GSI1: {
partitionKey: 'ORG#{{id}}#STATUS#{{status}}',
sortKey: 'ORG#{{id}}#ACTIVE#{{active}}',
type: INDEX_TYPE.GSI,
},
// specify LSI1 key
LSI1: {
sortKey: 'TICKETS#UPDATED_AT#{{updatedAt}}',
type: INDEX_TYPE.LSI,
},
},
})
export class Organisation {
@AutoGenerateAttribute({
strategy: AUTO_GENERATE_ATTRIBUTE_STRATEGY.UUID4,
})
id: string;
@Attribute()
name: string;
@Attribute()
status: string;
@Attribute()
active: boolean;
@AutoGenerateAttribute({
strategy: AUTO_GENERATE_ATTRIBUTE_STRATEGY.EPOCH_DATE,
autoUpdate: true, // this will make this attribute and any indexes referencing it auto update for any write operation
})
updatedAt: number;
}
Initialize default connection
The connection initialization steps slightly differs when using AWS SDK V2 vs V3.
When using AWS SDK V2
import {createConnection} from '@typedorm/core';
import {DocumentClientV2} from '@typedorm/document-client';
import AWS from 'aws-sdk';
const documentClient = new DocumentClientV2(new AWS.DynamoDB.DocumentClient());
// initialize with specifying list of entities
createConnection({
table: myGlobalTable,
entities: [Organisation],
documentClient, // <-- When documentClient is not provided, TypeDORM defaults to use the DocumentClientV2
});
// or initialize with specifying path match for entities
createConnection({
table: myGlobalTable,
entities: 'path-to-entities/*.entity.ts',
documentClient, // <-- When documentClient is not provided, TypeDORM defaults to use the DocumentClientV2
});
When using AWS SDK V3
Related Skills
tmux
344.1kRemote-control tmux sessions for interactive CLIs by sending keystrokes and scraping pane output.
claude-opus-4-5-migration
96.8kMigrate prompts and code from Claude Sonnet 4.0, Sonnet 4.5, or Opus 4.1 to Opus 4.5
Writing Hookify Rules
96.8kThis skill should be used when the user asks to "create a hookify rule", "write a hook rule", "configure hookify", "add a hookify rule", or needs guidance on hookify rule syntax and patterns.
review-duplication
99.8kUse this skill during code reviews to proactively investigate the codebase for duplicated functionality, reinvented wheels, or failure to reuse existing project best practices and shared utilities.
