Entities
In Mirror ORM, an Entity is a TypeScript class that accurately reflects a table in your database. Using Stage 3 Decorators to map your structure statically and ultra-fast.
The Anatomy of an Entity
Section titled “The Anatomy of an Entity”A Mirror entity is made up of three pillars: the class, the unique identifier and the data columns.
import { Entity, PrimaryColumn, Column } from 'mirror-orm';
@Entity('products')export class Product { @PrimaryColumn({ strategy: 'uuid_v7' }) id!: string;
@Column({ name: 'display_name' }) name!: string;
@Column({ type: 'number' }) price!: number;}1. The @Entity Decorator
Section titled “1. The @Entity Decorator”@Entity links your class to a table. If you do not pass a name, Mirror will use the class name as the name of the table in the database (respecting the defined case).
- Global Filters: You can define filters that apply to all queries of this entity (e.g. multi-tenancy).
- Performance: When the class is loaded, Mirror extracts the “blueprint” from the table and stores it in
MetadataRegistry.
2. Column Mapping (@Column)
Section titled “2. Column Mapping (@Column)”Mirror doesn’t try to guess types. It requires you to be explicit when data conversion is required.
- Native Type Casting: Through the
typeoption, Mirror injects the conversion logic directly into the JIT Hydrator. This means that converting a bank string to aDateorbooleanin JS happens at native V8 speed, without checking loops. - Data Privacy: Use
select: falsefor sensitive columns (likepassword_hash). They will never be brought from the bank unless you explicitly ask for them in afind({ select: [...] }).
3. Primary Key Strategies (@PrimaryColumn)
Section titled “3. Primary Key Strategies (@PrimaryColumn)”Mirror supports the most modern ID strategies on the market to avoid collisions and optimize indexing:
identity: Lets the bank generate the ID (SERIAL, BIGSERIAL, AUTO_INCREMENT).uuid_v7: Generates time-sortable IDs directly in Mirror (recommended for insertion performance in large tables).ulid/cuid2: Native support for URL-friendly and secure identifiers.custom: You define the generation function.
See also: The complete column options reference is in Column Decorators. To map relations between entities, see Relationships.