• Initialize a MikroORM instance.

    Initializes a MikroORM instance, and inherently making it available for future forks.

    No Nitro hooks are registered for the isntance, and auto forking only works with middleware, if allowed by the runtime config.

    Type Parameters

    • T extends MikroORM<IDatabaseDriver<Connection>, EntityManager<IDatabaseDriver<Connection>>> = MikroORM<IDatabaseDriver<Connection>, EntityManager<IDatabaseDriver<Connection>>>

      Type of the MikroORM instance. Typically, the MikroORM export of your MikroORM driver.

    Parameters

    • config: Options<IDatabaseDriver<Connection>, EntityManager<IDatabaseDriver<Connection>>>

      The config to use for the new instance.

    • name: string = 'default'

      The name to set for this instance.

    • Optional forkOptionsFactory: ((event, name) => undefined | ForkOptions)

      A function to create the fork options for a request. If left undefined, or returns undefined, the default fork options defined in the runtime config are used. This function is called the first time per request, when useEntityManager is used.

        • (event, name): undefined | ForkOptions
        • Parameters

          • event: H3Event<EventHandlerRequest>
          • name: string

          Returns undefined | ForkOptions

    Returns Promise<T>

    The initialized MikroORM instance (same as if you had called useOrm with the same name).

    Throws

    NuxtMikroOrmAlreadyInitialized When trying to initialize an instance that was previously initialized via initOrm or registerGlobalOrm, and still not closed via closeOrm.