Skip to main content

Installation

Only the core library is needed:
You can use any database driver:
  • PostgreSQL: pg, postgres
  • MySQL: mysql2
  • SQLite: better-sqlite3
  • Or any other driver

Define Your Domain

Create an aggregate with a child entity. Only the aggregate root (Order) is loaded and saved through the repository — child entities (OrderItem) are tracked automatically.

Implement Repository

Use getChanges() and toBatchOperations() to persist only what changed — including child entities — in the correct order for foreign keys.

PostgreSQL with pg

toBatchOperations() groups changes by entity and orders them to respect foreign keys: deletes run leaf → root, creates run root → leaf, updates run in any order.

Create Database Tables

Create your schema manually:

Use It

Transactions

Wrap multiple operations in a transaction with your database driver:

Validation

Validation works the same for aggregates and child entities:

Next Steps

Repository Pattern

Learn advanced repository patterns

Change Tracking

Understand how changes are tracked

Criteria API

Type-safe query building

Entities & Aggregates

Core DDD concepts