diff --git a/src/mikro-orm-core.module.ts b/src/mikro-orm-core.module.ts index f2a3fb5..dc719e3 100644 --- a/src/mikro-orm-core.module.ts +++ b/src/mikro-orm-core.module.ts @@ -152,15 +152,25 @@ export class MikroOrmCoreModule implements OnApplicationShutdown { } try { + let config; + if (!options || Object.keys(options).length === 0) { - const config = await ConfigurationLoader.getConfiguration(false); - return config.getDriver().createEntityManager(); + config = await ConfigurationLoader.getConfiguration(false); + } + + if (!config && 'useFactory' in options!) { + config = new Configuration(await options.useFactory!(), false); } - if ('useFactory' in options) { - const config = new Configuration(await options.useFactory!(), false); - return config.getDriver().createEntityManager(); + if (!config && options instanceof Configuration) { + config = options; } + + if (!config && typeof options === 'object' && options && 'driver' in options) { + config = new Configuration(options, false); + } + + return config?.getDriver().createEntityManager(); } catch { // ignore } diff --git a/tests/mikro-orm.module.test.ts b/tests/mikro-orm.module.test.ts index d4e062e..c4fb4f4 100644 --- a/tests/mikro-orm.module.test.ts +++ b/tests/mikro-orm.module.test.ts @@ -1,12 +1,9 @@ -import type { EntityRepository, Options } from '@mikro-orm/core'; -import { EntityManager, MikroORM } from '@mikro-orm/core'; +import { EntityRepository, Options, EntityManager, MikroORM } from '@mikro-orm/core'; import { SqliteDriver } from '@mikro-orm/sqlite'; import { Inject, Logger, Module, Scope } from '@nestjs/common'; import { ContextIdFactory } from '@nestjs/core'; -import type { TestingModule } from '@nestjs/testing'; -import { Test } from '@nestjs/testing'; -import type { MikroOrmOptionsFactory } from '../src'; -import { CONTEXT_NAMES, MikroOrmModule, getEntityManagerToken, getMikroORMToken, getRepositoryToken } from '../src'; +import { TestingModule, Test } from '@nestjs/testing'; +import { MikroOrmOptionsFactory, CONTEXT_NAMES, MikroOrmModule, getEntityManagerToken, getMikroORMToken, getRepositoryToken } from '../src'; import { Bar } from './entities/bar.entity'; import { Foo } from './entities/foo.entity';