Skip to main content

Installation

Install the TypeORM adapter:

Setup TypeORM

Create src/data-source.ts:
Initialize in your app:

Define Entity Schema

Create your TypeORM entity:

Define Your Aggregate

Create your domain model:

Create Mappers

ToDomain Mapper

Maps from TypeORM to Domain:

ToPersistence Mapper

Maps from Domain to TypeORM using TypeORMToPersistence:
  • onCreate receives EntityManager as second parameter
  • Use @Transactional() decorator for automatic transaction management
  • entityClasses Map is required for the BatchExecutor
  • onUpdate is handled automatically by TypeORMBatchExecutor - no need to override

Create Repository

Implement the repository:
Key points:
  • ToPersistenceMapper receives uow in constructor
  • Use getSearchableFields() to define which fields support search
  • Use getDefaultRelations() to eagerly load relations
  • typeormRepo is available from the base class for custom queries

Working with Relations

1:N Owned Relations

N:N with Junction Tables

Unit of Work with Transactions

Use the @Transactional decorator for automatic transaction management:
Or use the imperative API:

Advanced Queries

TypeORM gives you full access to QueryBuilder:

Transactional Outbox (optional)

If your aggregates emit domain events, pass an optional outboxStore in TypeORMRepositoryConfig. When set, save() persists uncommitted events to the outbox table in the same transaction as the aggregate — so events are not lost if the process crashes before dispatchAll(). See Transactional Outbox for the full setup (OutboxEntity, event bus decorator, background publisher). Repository wiring is documented under TypeORM Integration → Transactional Outbox.

Next Steps

TypeORM Integration

Deep dive into TypeORM adapter features

Transactional Outbox

Guaranteed domain event delivery with the outbox pattern

Repository Pattern

Learn advanced repository patterns

Change Tracking

Understand how changes are tracked

Transactions

Advanced transaction management