MikroORM Setup
MikroORM is the alternative ORM in Ever Gauzy, providing stricter metadata validation, identity maps, and the Unit of Work pattern.
Configuration
Enabling MikroORM
# .env
DB_ORM=mikro-orm
Connection Options
MikroORM uses a similar database configuration to TypeORM:
MikroOrmModule.forRootAsync({
useFactory: (configService: ConfigService) => ({
type: configService.get("DB_TYPE"),
host: configService.get("DB_HOST"),
port: configService.get("DB_PORT"),
dbName: configService.get("DB_NAME"),
user: configService.get("DB_USER"),
password: configService.get("DB_PASS"),
entities: [...coreEntities, ...pluginEntities],
discovery: { disableDynamicFileAccess: true },
allowGlobalContext: true,
}),
});
Key Differences from TypeORM
| Feature | TypeORM | MikroORM |
|---|---|---|
| Pattern | Active Record + Data Mapper | Unit of Work |
| Change Tracking | Manual save | Automatic (Identity Map) |
| Metadata | Decorators at runtime | Stricter validation |
| Flushing | Immediate save() | Batch em.flush() |
| Relations | Eager/lazy optional | Reference wrappers |
| Entity Creation | repo.create() | em.create() |