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.
1. Installation
Section titled “1. Installation”Install the database core and driver you will use:
# PostgreSQLpnpm add mirror-orm pg# MySQL / MariaDBpnpm add mirror-orm mysql2# SQLitepnpm add mirror-orm better-sqlite3# SQL Serverpnpm add mirror-orm mssql2. TypeScript Configuration
Section titled “2. TypeScript Configuration”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+.
3. Establishing Connection
Section titled “3. Establishing Connection”Mirror offers named static methods for each bank, accepting both a Connection String and a detailed configuration object.
1. Postgres
Section titled “1. Postgres”Uses the pg driver. Supports SSL and Read Replicas.
import { Connection } from 'mirror-orm';
// Connection Stringawait Connection.postgres('postgresql://user:password@localhost:5432/dbname');
// Objeto de Configuraçãoawait Connection.postgres({ host: 'localhost', user: 'admin', password: 'password', database: 'mirror_db', port: 5432, ssl: true // Necessário para Neon/Supabase/RDS});2. MySQL
Section titled “2. MySQL”Uses the mysql2 driver.
import { Connection } from 'mirror-orm';
// Connection Stringawait Connection.mysql('mysql://user:password@localhost:3306/dbname');
// Objeto de Configuraçãoawait Connection.mysql({ host: 'localhost', user: 'root', password: 'password', database: 'mirror_db'});3. SQLite
Section titled “3. SQLite”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' });4. SQL Server (MSSQL)
Section titled “4. SQL Server (MSSQL)”Uses the mssql driver.
import { Connection } from 'mirror-orm';
// Connection Stringawait Connection.sqlServer('mssql://user:pass@localhost:1433/db?encrypt=true');
// Objeto de Configuraçãoawait Connection.sqlServer({ server: 'localhost', user: 'sa', password: 'Password123!', database: 'mirror_db', options: { encrypt: true, trustServerCertificate: true }});4. First entity
Section titled “4. First entity”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.