Overview
EntitySchemaRegistry provides a centralized mapping between your domain entities and database tables. It handles field name translations, foreign key relationships, and collection configurations - making your mappers cleaner and more maintainable.
Why Use Schema Registry?
Centralized Mapping
Define all entity-to-table mappings in one place
Field Translation
Map camelCase domain fields to snake_case database columns
FK Management
Configure parent-child relationships and foreign keys
Collection Types
Distinguish between owned (1:N) and reference (N:N) relations
Basic Usage
Registering Entities
Bulk Registration
Field Mapping
Map domain property names to database column names:Mapping Entity Data
Transform a complete domain entity to database format:Mapping Partial Fields
Transform only specific fields (useful for updates):Parent-Child Relationships
Configure foreign key relationships for 1:N (owned) relationships:Getting FK Information
Custom Primary Keys
By default, the registry assumes every table uses anid column as the primary key. For tables that use a different PK (common in 1:1 child tables sharing the parent’s identity), configure primaryKey.
primaryKey is the database column name, not a domain property. Adapters always read the identity from entity.id and map it to that column. Setting primaryKey: "factoryId" produces where: { factoryId: entity.id.value } — not { factoryId: entity.factoryId }.
Profile.id the same value as Factory.id when creating the child. Batch executors and repositories use buildWhereById / buildWhereByIds to resolve the correct column automatically.
Composite primary keys are not supported in v1.
Collection Configuration
Configure how collections (1:N and N:N) should be handled:Collection Types
Checking Collection Types
Mapping Domain Field Names to ORM Field Names
When the domain property name and the ORM relation field name differ, userelationName to configure the mapping. ORM adapters such as PrismaBatchExecutor use getRelationFieldName() to resolve the correct field for connect/disconnect operations.
Query Methods
Using with Mappers
The registry is commonly used in persistence mappers:Using with BatchExecutor
The registry integrates withPrismaBatchExecutor for automatic field mapping: