class UnitOfWork
implements IUnitOfWork
Since 0.1.0

Concrete Unit of Work that holds a transaction and delegates repository creation to the database service within the transaction boundary.

Constructors

UnitOfWork(
_transaction: ITransaction,
_repoFactory: (entity: string) => IRepository<unknown>,
_adapterType?: DatabaseAdapterType
)

Creates a Unit of Work over one active adapter transaction.

Methods

[DRIZZLE_QUERY_HANDLE](): NativeDrizzleQueryHandle

Provide the transaction-scoped native Drizzle object through the internal protocol.

commit(): Promise<void>

Commit the transaction. Must be called after all operations complete.

getRepository<Entity, Id extends EntityKey = string>(entity: string): IRepository<Entity, Id>

Get a transaction-scoped repository for the named entity.

rollback(): Promise<void>

Roll back the transaction. Called automatically by DatabaseService on errors, but can also be called explicitly.

Usage

import { UnitOfWork } from "database-plugin/src/index.ts";