Skip to main content
Version: 5.9

MikroORM

Helper class for bootstrapping the MikroORM.

Hierarchy

  • MikroORM<MySqlDriver>
    • MikroORM

Index

Constructors

constructor

  • new MikroORM(options: Options<MySqlDriver> | Configuration<MySqlDriver>): MySqlMikroORM
  • Parameters

    • options: Options<MySqlDriver> | Configuration<MySqlDriver>

    Returns MySqlMikroORM

Properties

readonlyconfig

config: Configuration<MySqlDriver>

em

em: SqlEntityManager<MySqlDriver> & EntityManager<IDatabaseDriver<Connection>>

The global EntityManager instance. If you are using RequestContext helper, it will automatically pick the request specific context under the hood

Accessors

entityGenerator

  • get entityGenerator(): IEntityGenerator
  • Shortcut for orm.getEntityGenerator()


    Returns IEntityGenerator

migrator

  • get migrator(): IMigrator
  • Shortcut for orm.getMigrator()


    Returns IMigrator

schema

  • get schema(): ReturnType<ReturnType<D[getPlatform]>[getSchemaGenerator]>
  • Shortcut for orm.getSchemaGenerator()


    Returns ReturnType<ReturnType<D[getPlatform]>[getSchemaGenerator]>

seeder

  • get seeder(): ISeedManager
  • Shortcut for orm.getSeeder()


    Returns ISeedManager

Methods

close

  • close(force?: boolean): Promise<void>
  • Closes the database connection.


    Parameters

    • force: boolean = false

    Returns Promise<void>

connect

  • connect(): Promise<MySqlDriver>
  • Connects to the database.


    Returns Promise<MySqlDriver>

discoverEntities

  • discoverEntities(): Promise<void>
  • Returns Promise<void>

discoverEntity

  • discoverEntity(entities: Constructor | Constructor[]): Promise<void>
  • Allows dynamically discovering new entity by reference, handy for testing schema diffing.


    Parameters

    • entities: Constructor | Constructor[]

    Returns Promise<void>

getEntityGenerator

  • getEntityGenerator<T>(): T
  • Gets the EntityGenerator.


    Type parameters

    • T: IEntityGenerator = IEntityGenerator

    Returns T

getMetadata

  • getMetadata(): MetadataStorage
  • getMetadata<Entity>(entityName: EntityName<Entity>): EntityMetadata<Entity>
  • Gets the MetadataStorage.


    Returns MetadataStorage

getMigrator

  • getMigrator<T>(): T
  • Gets the Migrator.


    Type parameters

    • T: IMigrator = IMigrator

    Returns T

getSchemaGenerator

  • getSchemaGenerator(): SchemaGenerator
  • Gets the SchemaGenerator.


    Returns SchemaGenerator

getSeeder

  • getSeeder<T>(): T
  • Gets the SeedManager


    Type parameters

    • T: ISeedManager = ISeedManager

    Returns T

isConnected

  • isConnected(): Promise<boolean>
  • Checks whether the database connection is active.


    Returns Promise<boolean>

reconnect

  • reconnect(options?: Options): Promise<void>
  • Reconnects, possibly to a different database.


    Parameters

    • options: Options = {}

    Returns Promise<void>

staticinit

  • init<D>(options?: Options<D> | Configuration<D>, connect?: boolean): Promise<MikroORM<D>>
  • Initialize the ORM, load entity metadata, create EntityManager and connect to the database. If you omit the options parameter, your CLI config will be used.


    Type parameters

    • D: IDatabaseDriver<Connection, D> = MySqlDriver

    Parameters

    • optionaloptions: Options<D> | Configuration<D>
    • connect: boolean = true

    Returns Promise<MikroORM<D>>