Command-line interface tool for MikroORM TypeScript ORM providing database management, migrations, schema operations, and entity generation
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
MikroORM CLI entity management commands for generating TypeScript entity classes from existing database schemas. This reverse-engineering functionality helps migrate existing databases to MikroORM.
Generates TypeScript entity classes based on the current database schema. Supports both file output and console display for review.
/**
* Generate entities from database schema command
*/
command: "generate-entities"
interface GenerateEntitiesOptions extends BaseArgs {
save?: boolean; // Save entities to filesystem (--save / -s)
dump?: boolean; // Output entities to console (--dump / -d)
path?: string; // Directory path where to save entities (--path / -p)
schema?: string; // Generate entities only for specific schema (--schema)
}Usage Examples:
# Generate and display entities in console
mikro-orm generate-entities --dump
# Generate and save entities to filesystem
mikro-orm generate-entities --save
# Save entities to specific directory
mikro-orm generate-entities --save --path ./src/entities
# Generate entities for specific schema only
mikro-orm generate-entities --save --schema public
# Generate with custom configuration
mikro-orm generate-entities --dump --config ./orm.config.jsAt least one of these options must be provided:
--save / -s: Save generated entities to filesystem--dump / -d: Display generated entities in console--path / -p: Set directory path where entities will be saved (used with --save)--schema: Generate entities only for the specified database schema--config: Path to ORM configuration file(s)--contextName / --context: Configuration context nameThe entity generator creates TypeScript classes with:
@Entity() decorators with table names@Property(), @PrimaryKey(), etc.--save nor --dump is provided--save--pathEntity generation works with:
Example generated entity:
import { Entity, PrimaryKey, Property, ManyToOne } from '@mikro-orm/core';
import { User } from './User';
@Entity()
export class Post {
@PrimaryKey()
id!: number;
@Property()
title!: string;
@Property({ type: 'text' })
content!: string;
@Property()
createdAt: Date = new Date();
@ManyToOne(() => User)
author!: User;
}Entity generation uses these configuration options:
interface EntityGeneratorConfiguration {
discovery?: {
warnWhenNoEntities?: boolean; // Suppress entity warnings during generation
};
baseDir?: string; // Base directory for resolving paths
entities?: string[]; // Entity paths (not used during generation)
entitiesTs?: string[]; // TypeScript entity paths (not used during generation)
}