Back to Mikro Orm

@mikro-orm/entity-generator

packages/entity-generator/README.md

7.0.141.3 KB
Original Source

@mikro-orm/entity-generator

Entity generator for MikroORM. Generates entity definitions from an existing database schema, supporting both decorator-based and defineEntity-based output.

Installation

sh
npm install @mikro-orm/entity-generator

Usage

Via CLI

sh
npx mikro-orm generate-entities --save --path=./src/entities

Programmatic API

typescript
import { MikroORM } from '@mikro-orm/postgresql';

const orm = await MikroORM.init({ ... });
const generator = orm.entityGenerator;

// Generate entity files from the current database schema
const dump = await generator.generate({
  save: true,
  path: './src/entities',
});

Features

  • Generates entities from any supported SQL or MongoDB database
  • Output formats: defineEntity helper (default), decorators, or EntitySchema
  • Detects and generates relations, indexes, enums, and embeddables
  • Configurable naming conventions and output options
  • Bidirectional relation generation with Ref wrapper support

Documentation

See the official MikroORM documentation.

License

Copyright © 2018-present Martin Adámek. Licensed under the MIT License.