TypeORM
The @dugongjs/typeorm
package provides adapter implementations for TypeORM.
It has adapters for the following ports:
Port | Adapter |
---|---|
IDomainRepository | DomainRepositoryTypeOrm |
ISnapshotRepository | SnapshotRepositoryTypeOrm |
IConsumedMessageRepository | ConsumedMessageRepositoryTypeOrm |
ITransactionManager | TransactionManagerTypeOrm |
IMessageProducer | OutboxMessageProducerTypeOrm |
IOutboundMessageMapper | OutboxMessageMapperTypeOrm |
Installation
To get started, install the following packages:
npm install typeorm @dugongjs/typeorm
Configuring DataSource
Follow the TypeORM documentation to get started. When you create your DataSource
, add the following entities:
import { ConsumedMessageEntity, DomainEventEntity, SnapshotEntity } from "@dugongjs/typeorm";
import { DataSource, type DataSourceOptions } from "typeorm";
const dataSourceOptions: DataSourceOptions = {
type: "postgres",
host: "localhost",
port: 5432,
username: "test",
password: "test",
database: "test",
entities: [
// Your other entities...
DomainEventEntity,
SnapshotEntity,
ConsumedMessageEntity
]
};
const dataSource = new DataSource(dataSourceOptions);
tip
If you wish to use the outbox pattern, also add OutboxEntity
to the list of entities.