MikroORM
TypeScript ORM with identity map, unit of work, and support for SQL and MongoDB through a single entity model.
Official Documentation ↗v7.2.7. Check the official docs for the latest API surface.Installation
npm install @mikro-orm/core @mikro-orm/postgresqlpnpm add @mikro-orm/core @mikro-orm/postgresqlMethods
No methods match this filter.
Overview
MikroORM is a TypeScript ORM offering an identity map, unit of work, and one entity model across SQL databases and MongoDB. This reference lists the most frequently used APIs with accurate signatures and runnable snippets.
Core APIs
MikroORM.init— Initializes the ORM with entities, a driver, and connection settings.em.flush— Commits all pending entity changes tracked by the unit of work in one transaction.em.find— Loads entities matching a filter, with optional population of relations.
Example
const { MikroORM } = require('@mikro-orm/core');
const orm = await MikroORM.init({
entities: ['./dist/entities'],
dbName: 'app',
type: 'postgresql',
});
Notes
Changes are tracked in memory and committed at flush, so forgetting to flush silently drops them. Identity map semantics require per-request entity managers.
Verification
Create an entity, flush, then reload it in a fresh context and confirm the persisted fields match.
API reference evidence
Fetched from official sources on 2026-11-08T17:49:10+08:00 via WebFetch https://mikro-orm.io/api/core/class/MikroORM.
MikroORM.init→ signature from https://mikro-orm.io/api/core/class/MikroORM; official text: “init <D, EM, Entities>(options): Promise<MikroORM<D, EM, Entities>>”em.flush→ signature from https://mikro-orm.io/api/core/class/EntityManager; official text: “flush (): Promise” em.find→ signature from https://mikro-orm.io/api/core/class/EntityManager; official text: “find <Entity, Hint, Fields, Excludes, Using>(entityName, where, options): Promise<Loaded<Entity, Hint, Fields, Excludes>[]>”
FAQ
- How does the identity map help?
- Each entity is represented once per request context, so the same row resolves to one object and change tracking stays consistent.
- What is the unit of work?
- It queues inserts, updates, and deletes and applies them in dependency order at flush time inside a transaction.
- How do I run raw SQL?
- Use the connection execute method, or knex-style query builder through em.getKnex() when you need lower-level access.
Report a problem with this API docOpens a pre-filled issue on GitHub.