import React, { useState, useEffect, useRef, useCallback } from 'react'; import Layout from '@theme/Layout'; import Link from '@docusaurus/Link'; import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; import useBaseUrl from '@docusaurus/useBaseUrl'; import CodeBlock from '@theme/CodeBlock'; import styles from './styles.module.css'; const features = [ { title: 'Unit of Work & Identity Map', docsUrl: 'docs/unit-of-work', icon: ( ), description: 'Automatic change tracking and batched queries. All changes are wrapped in implicit transactions when you call em.flush().', }, { title: 'Fully Type-Safe', docsUrl: 'docs/type-safe-relations', icon: ( ), description: 'Type-safe queries, populate hints, and entity operations. Even string-based filters and relations are validated at compile time.', }, { title: 'Multiple Entity Definition Styles', docsUrl: 'docs/defining-entities', icon: ( ), description: 'Choose your style: defineEntity with full type inference, decorators, or EntitySchema. No lock-in to a single approach.', }, { title: 'Filters & Soft Delete', docsUrl: 'docs/filters', icon: ( ), description: 'Global and entity-level query filters for multi-tenancy, soft deletes, and more. Applied automatically to every query.', }, { title: 'SQL & NoSQL', docsUrl: 'docs/usage-with-sql', icon: ( ), description: 'First-class support for MongoDB, PostgreSQL, MySQL, MariaDB, SQLite, libSQL, MS SQL Server, and more.', }, { title: 'Schema Management', docsUrl: 'docs/migrations', icon: ( ), description: 'Prototype with SchemaGenerator, version with Migrations, or introspect existing databases with EntityGenerator.', }, { title: 'Smart Populate & Loading', docsUrl: 'docs/populating-relations', icon: ( ), description: 'Type-checked populate hints with auto-joined loading strategies. Control exactly what gets loaded and how.', }, { title: 'Events & Lifecycle', docsUrl: 'docs/events', icon: ( ), description: 'Powerful event system with entity lifecycle hooks, onFlush events, and metadata-aware QueryBuilder.', }, { title: 'Seeding & Factories', docsUrl: 'docs/seeding', icon: ( ), description: 'Seed your database with realistic test data using entity factories. Define reusable blueprints and generate data for development and testing.', }, { title: 'First-Class Kysely Integration', docsUrl: 'docs/kysely', icon: ( ), description: 'Use Kysely\'s type-safe SQL query builder directly with your MikroORM entities. Full autocompletion for table and column names.', }, ]; const databases = [ { name: 'PostgreSQL', logo: 'img/databases/postgresql.svg', docsUrl: 'docs/usage-with-sql' }, { name: 'MySQL', logo: 'img/databases/mysql.svg', docsUrl: 'docs/usage-with-sql' }, { name: 'MariaDB', logo: 'img/databases/mariadb.svg', docsUrl: 'docs/usage-with-sql' }, { name: 'SQLite', logo: 'img/databases/sqlite.svg', docsUrl: 'docs/usage-with-sqlite' }, { name: 'MongoDB', logo: 'img/databases/mongodb.svg', docsUrl: 'docs/usage-with-mongo' }, { name: 'MS SQL', logo: 'img/databases/mssql.svg', docsUrl: 'docs/usage-with-sql#ms-sql-server-limitations' }, { name: 'libSQL', logo: 'img/databases/libsql.svg', docsUrl: 'docs/usage-with-sqlite#using-libsql--turso' }, { name: 'CockroachDB', logo: 'img/databases/cockroachdb.svg', docsUrl: 'docs/usage-with-cockroachdb' }, { name: 'Oracle', logo: 'img/databases/oracle.svg', docsUrl: 'docs/usage-with-sql#oracle-limitations' }, { name: 'Turso', logo: 'img/databases/turso.svg', docsUrl: 'docs/usage-with-sqlite#using-turso-embedded-database' }, { name: 'Cloudflare D1', logo: 'img/databases/cloudflare-d1.svg', docsUrl: 'docs/usage-with-sqlite#using-cloudflare-d1' }, { name: 'PGlite', logo: 'img/databases/pglite.svg', docsUrl: 'docs/usage-with-pglite' }, ]; function Feature({ title, icon, description, docsUrl }) { return (
{icon}

{title}

{description}

); } function FeatureScroll() { const trackRef = useRef(null); const paused = useRef(false); useEffect(() => { const el = trackRef.current; if (!el) return; let animId; const speed = 0.4; const step = () => { if (!paused.current) { el.scrollLeft += speed; // seamless loop: when the first set scrolls away, reset if (el.scrollLeft >= el.scrollWidth / 2) { el.scrollLeft = 0; } } animId = requestAnimationFrame(step); }; animId = requestAnimationFrame(step); return () => cancelAnimationFrame(animId); }, []); const pause = useCallback(() => { paused.current = true; }, []); const resume = useCallback(() => { paused.current = false; }, []); return (
{features.map((props, idx) => ( ))} {features.map((props, idx) => ( ))}
); } const driverPackages = [ '@mikro-orm/postgresql', '@mikro-orm/pglite', '@mikro-orm/mysql', '@mikro-orm/mariadb', '@mikro-orm/sqlite', '@mikro-orm/mongodb', '@mikro-orm/libsql', '@mikro-orm/sql-js', '@mikro-orm/mssql', '@mikro-orm/oracledb', ]; function InstallSnippet() { const [copied, setCopied] = useState(false); const [driverIndex, setDriverIndex] = useState(0); const [animating, setAnimating] = useState(false); useEffect(() => { const interval = setInterval(() => { setAnimating(true); setTimeout(() => { setDriverIndex(i => (i + 1) % driverPackages.length); setAnimating(false); }, 200); }, 2500); return () => clearInterval(interval); }, []); const pkg = driverPackages[driverIndex]; const command = `npm install ${pkg}`; const handleCopy = () => { navigator.clipboard.writeText(command); setCopied(true); setTimeout(() => setCopied(false), 2000); }; return (
$ npm install {pkg} {copied ? ( ) : ( <> )}
); } const entityTabs = [ { id: 'defineEntity', label: 'defineEntity', code: `import { defineEntity, InferEntity, p } from '@mikro-orm/core'; export const Book = defineEntity({ name: 'Book', properties: { id: p.number().primary(), title: p.string(), author: () => p.manyToOne(Author).ref(), tags: () => p.manyToMany(Tag), }, }); export type IBook = InferEntity;`, }, { id: 'reflect-metadata', label: 'reflect-metadata', code: `@Entity() export class Book { [EntityName]?: 'Book'; @PrimaryKey() id: number; @Property() title: string; @ManyToOne(() => Author, { ref: true }) author: Ref; @ManyToMany(() => Tag) tags = new Collection(this); }`, }, { id: 'ts-morph', label: 'ts-morph', code: `@Entity() export class Book { [EntityName]?: 'Book'; @PrimaryKey() id: number; @Property() title: string; @ManyToOne() author: Ref; @ManyToMany() tags = new Collection(this); }`, }, { id: 'entitySchema', label: 'EntitySchema', code: `export interface IBook { [EntityName]?: 'Book'; id: number; title: string; author: Ref; tags: Collection; } export const Book = new EntitySchema({ name: 'Book', properties: { id: { type: 'number', primary: true }, title: { type: 'string' }, author: { kind: 'm:1', entity: () => 'Author', ref: true }, tags: { kind: 'm:n', entity: () => 'Tag' }, }, });`, }, ]; const queryTabs = [ { id: 'em', label: 'EntityManager', code: `// fully type-safe queries const books = await em.find(Book, { author: { name: 'Tolkien' }, }, { populate: ['author.profile'], // type-checked! orderBy: { title: 'asc' }, }); // all changes are tracked automatically books[0].title = 'Updated Title'; em.remove(books[1]); // single flush = one transaction, batched queries await em.flush();`, }, { id: 'qb', label: 'QueryBuilder', code: `const books = await em.createQueryBuilder(Book, 'b') .select('*') .leftJoinAndSelect('b.author', 'a') .where({ 'a.name': 'Tolkien' }) .orderBy({ title: 'asc' }) .getResultList(); // or with raw SQL fragments const stats = await em.createQueryBuilder(Book, 'b') .select([raw('count(*) as count'), 'b.author']) .groupBy('b.author') .having({ [raw('count(*)')]: { $gte: 3 } }) .getResultList();`, }, { id: 'kysely', label: 'Kysely', code: `// first-class Kysely integration const kysely = orm.em.getKysely({ tableNamingStrategy: 'entity', columnNamingStrategy: 'property', }); const rows = await kysely .selectFrom('Book as b') .innerJoin('Author as a', 'a.id', 'b.author') .select(['b.title', 'a.name']) .where('a.name', '=', 'Tolkien') .orderBy('b.title', 'asc') .execute(); // fully typed — entity and property names // auto-completed from your entity metadata`, }, { id: 'loaded', label: 'Loaded Type', code: `// enforce loaded relations via function signature function renderBookCard( book: Loaded, ) { // all accessed relations guaranteed to be loaded return { title: book.title, author: book.author.$.name, bio: book.author.$.profile.$.bio, tags: book.tags.$.map(t => t.name), }; } // populate must match — or it won't compile const book = await em.findOneOrFail(Book, 1, { populate: ['author.profile', 'tags'], }); renderBookCard(book); // works! const raw = await em.findOneOrFail(Book, 1); renderBookCard(raw); // compile error!`, }, ]; function CodeExample() { const [activeTab, setActiveTab] = useState('defineEntity'); const [activeQueryTab, setActiveQueryTab] = useState('em'); return (

Define, Query, Done

Define entities your way, query with a clean type-safe API

{entityTabs.map(tab => ( ))}
{entityTabs.find(t => t.id === activeTab).code}
{queryTabs.map(tab => ( ))}
{queryTabs.find(t => t.id === activeQueryTab).code}
); } function Home() { const context = useDocusaurusContext(); const { siteConfig = {} } = context; return ( {/* Hero */}

TypeScript ORM{'\n'}built on proven patterns

Based on Data Mapper, Unit of Work, and Identity Map patterns. Build type-safe, performant database layers with minimal boilerplate.

Get Started GitHub