Skip to content

Getting started

Mirror ORM is an ultra-high performance Data Mapper for Node.js, focused on near-zero overhead and strict typing. It uses JIT (Just-In-Time) compilation to ensure that entity hydration is the fastest in the ecosystem.

Install the database core and driver you will use:

Terminal window
# PostgreSQL
pnpm add mirror-orm pg
Terminal window
# MySQL / MariaDB
pnpm add mirror-orm mysql2
Terminal window
# SQLite
pnpm add mirror-orm better-sqlite3
Terminal window
# SQL Server
pnpm add mirror-orm mssql

Mirror uses native Stage 3 Decorators (TS 5.0+). Unlike other ORMs, do not enable experimentalDecorators, as Mirror follows the native TC39 standard.

In your tsconfig.json:

{
"compilerOptions": {
"target": "ES2022",
"module": "ESNext",
"moduleResolution": "bundler"
}
}

Node 20 note: Mirror automatically injects the polyfill for Symbol.metadata. You don’t need extra configuration for decorators to work in Node.js v20.20.1+.

Mirror offers named static methods for each bank, accepting both a Connection String and a detailed configuration object.

Uses the pg driver. Supports SSL and Read Replicas.

import { Connection } from 'mirror-orm';
// Connection String
await Connection.postgres('postgresql://user:password@localhost:5432/dbname');
// Objeto de Configuração
await Connection.postgres({
host: 'localhost',
user: 'admin',
password: 'password',
database: 'mirror_db',
port: 5432,
ssl: true // Necessário para Neon/Supabase/RDS
});

Uses the mysql2 driver.

import { Connection } from 'mirror-orm';
// Connection String
await Connection.mysql('mysql://user:password@localhost:3306/dbname');
// Objeto de Configuração
await Connection.mysql({
host: 'localhost',
user: 'root',
password: 'password',
database: 'mirror_db'
});

Uses the better-sqlite3 driver. Since SQLite is a local file, the URL is the file path.

const conn = await Connection.sqlite({ database: './app.db' });

Uses the mssql driver.

import { Connection } from 'mirror-orm';
// Connection String
await Connection.sqlServer('mssql://user:pass@localhost:1433/db?encrypt=true');
// Objeto de Configuração
await Connection.sqlServer({
server: 'localhost',
user: 'sa',
password: 'Password123!',
database: 'mirror_db',
options: { encrypt: true, trustServerCertificate: true }
});

The mapping in Mirror is explicit to ensure that JIT Hydrator knows exactly what to process.

import { Entity, Column, PrimaryColumn, CreatedAt, UpdatedAt } from 'mirror-orm';
@Entity('users')
class User {
@PrimaryColumn({ strategy: 'identity' })
id!: number;
@Column()
name!: string;
@Column({ nullable: true })
email!: string | null;
@CreatedAt()
createdAt!: Date;
@UpdatedAt()
updatedAt!: Date;
}

Next steps: See the complete decorator reference in Entities and Column Decorators. To make your first query, see the Repository API.