CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-mikro-orm--cli

Command-line interface tool for MikroORM TypeScript ORM providing database management, migrations, schema operations, and entity generation

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

entities.mddocs/

Entity Commands

MikroORM CLI entity management commands for generating TypeScript entity classes from existing database schemas. This reverse-engineering functionality helps migrate existing databases to MikroORM.

Capabilities

Generate Entities

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.js

Command Options

Required Options

At least one of these options must be provided:

  • --save / -s: Save generated entities to filesystem
  • --dump / -d: Display generated entities in console

Optional Options

  • --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 name

Generated Entity Features

The entity generator creates TypeScript classes with:

  • Entity Decorators: Proper @Entity() decorators with table names
  • Property Decorators: Column mappings with @Property(), @PrimaryKey(), etc.
  • Type Definitions: Correct TypeScript types based on database column types
  • Relationships: Foreign key relationships as entity references
  • Indexes: Database indexes represented as entity metadata
  • Constraints: Unique constraints and other database constraints

Error Handling

Common Errors

  • Missing required options: Command fails if neither --save nor --dump is provided
  • Database connection errors: Cannot generate entities without valid database connection
  • Schema not found: Specified schema must exist in the database
  • Permission errors: File system write permissions required when using --save
  • Path errors: Target directory must exist or be creatable when using --path

Entity Generation Issues

  • Unsupported column types: Some database-specific types may not map perfectly to TypeScript
  • Complex relationships: Circular dependencies may require manual adjustment
  • Naming conflicts: Generated class names may conflict with TypeScript reserved words
  • Case sensitivity: Database naming conventions may require adjustment for TypeScript

Database Support

Entity generation works with:

  • PostgreSQL: Full support including schemas, custom types, and complex relationships
  • MySQL/MariaDB: Complete support with proper type mapping
  • SQLite: Basic support with standard SQL types
  • MongoDB: Not applicable (document-based, not schema-based)

Generated Code Example

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;

}

Configuration

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)
}

docs

cache.md

database.md

debug.md

entities.md

helper-api.md

index.md

migrations.md

schema.md

seeders.md

tile.json