Skip to content

Commit

Permalink
fix: improve support for driver specific imports
Browse files Browse the repository at this point in the history
Related: #123
  • Loading branch information
B4nan committed May 19, 2024
1 parent 3656eaf commit a71c354
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
20 changes: 15 additions & 5 deletions src/mikro-orm-core.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
9 changes: 3 additions & 6 deletions tests/mikro-orm.module.test.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down

0 comments on commit a71c354

Please sign in to comment.