Skip to content
This repository has been archived by the owner on Oct 10, 2019. It is now read-only.

Latest commit

 

History

History
43 lines (32 loc) · 988 Bytes

entity-generator.md

File metadata and controls

43 lines (32 loc) · 988 Bytes


Entity Generator

To generate entities from existing database schema, you can use EntityGenerator helper.

You can use it via CLI:

npx mikro-orm generate-entities --dump  # Dumps all generated entities
npx mikro-orm generate-entities --save --path=./my-entities  # Saves entities into given directory

Or you can create simple script where you initialize MikroORM like this:

./generate-entities.ts

import { MikroORM } from 'mikro-orm';

(async () => {
  const orm = await MikroORM.init({
    dbName: 'your-db-name',
    // ...
  });
  const generator = orm.getEntityGenerator();
  const dump = await generator.generate({ 
    save: true,
    baseDir: process.cwd() + '/my-entities',
  });
  console.log(dump);
  await orm.close(true);
})();

Then run this script via ts-node (or compile it to plain JS and use node):

$ ts-node generate-entities

← Back to table of contents