Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Connection
✓ import { Connection } from 'mirror-orm'
✗ const { Connection } = require('mirror-orm')
mirror-orm is ESM-only; requires Node >=20 and module setting in tsconfig.
Entity, Column, PrimaryColumn
✓ import { Entity, Column, PrimaryColumn } from 'mirror-orm'
✗ import { Entity } from 'mirror-orm/entity'
All decorators are exported from the main package index.
Repository
✓ import type { Repository } from 'mirror-orm'
✗ import { Repository } from 'mirror-orm/Repository'
Repository is an interface; use type import to avoid runtime overhead.
Defines a User entity, creates an in-memory SQLite database, syncs schema, and performs insert/find operations.
import { Connection, Entity, Column, PrimaryColumn, CreatedAt } from 'mirror-orm';
@Entity('users')
class User {
@PrimaryColumn({ strategy: 'identity' })
id!: number;
@Column()
name!: string;
@Column({ nullable: true })
email!: string | null;
@CreatedAt()
createdAt!: Date;
}
const conn = await Connection.sqlite({ database: ':memory:' });
await conn.sync({ force: true });
const repo = conn.getRepository(User);
const user = await repo.save(Object.assign(new User(), { name: 'Alice', email: 'alice@example.com' }));
const found = await repo.findById(1);
console.log(found.name); // Alice
await conn.close();
Debug
Known issues
breakingRequires Node.js >=20.0.0 and pnpm >=10.0.0fixUpdate Node.js to v20+ and pnpm to v10+.
affects: >=1.0.0
breakingStage 3 decorators only; experimentalDecorators must be false in tsconfigfixSet "experimentalDecorators": false in tsconfig.json and ensure target is ES2022 or later.
affects: >=1.0.0
breakingESM-only package. CommonJS require() will fail.fixUse import syntax and set "type": "module" in package.json or use .mjs extension.
affects: >=1.0.0
deprecatedNo deprecated features currently reported.
gotchaRepository methods (e.g., findById) return undefined for none found, not null.fixCheck for undefined explicitly: const user = await repo.findById(id); if (user === undefined) ...
affects: >=1.0.0
gotchaConnection.sync({ force: true }) drops and recreates tables. Use with caution in production.fixUse migrations or set force: false to only create missing tables.
affects: >=1.0.0
Errors
Common errors & fixes
Experimental decorators warning: The 'experimentalDecorators' option is required for decorators to work.
tsconfig.json has experimentalDecorators: true or is missing.
fixSet "experimentalDecorators": false in tsconfig.json and update target to ES2022.
TypeError: Class constructor User cannot be invoked without 'new'
Using require() instead of import for ESM package.
fixChange to import { User } from 'mirror-orm' and use new User(). Cannot find module 'pg' or 'better-sqlite3'
Database driver not installed.
fixInstall the appropriate driver: npm install pg (PostgreSQL), better-sqlite3 (SQLite), etc.
Error: No metadata for "User". Did you forget to add @Entity?
Entity class is missing @Entity decorator or not registered before use.
fixAdd @Entity('tablename') to the class and ensure it is imported before calling getRepository. Audit
Dependencies
better-sqlite3optionalRequired for SQLite support
mssqloptionalRequired for SQL Server support
mysql2optionalRequired for MySQL support
pgoptionalRequired for PostgreSQL support