Skip to content

Commit 1e836d1

Browse files
committed
docs(json-api-nestjs-microorm): Change readme
1 parent 0d3c852 commit 1e836d1

File tree

1 file changed

+33
-0
lines changed
  • libs/json-api/json-api-nestjs-microorm

1 file changed

+33
-0
lines changed

libs/json-api/json-api-nestjs-microorm/README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,36 @@ export type MicroOrmParam = {
1818
};
1919

2020
```
21+
22+
## NOTE: MikroORM Default Named Context Issue in NestJS
23+
24+
[@mikro-orm/nestjs](https://github.com/mikro-orm/nestjs) does not create a [default named context](https://github.com/mikro-orm/nestjs/discussions/214).
25+
26+
As a result, the module initialization behaves differently depending on whether a single or multiple connections are used.
27+
More specifically, the [dependency injection token for MikroORM differs](https://github.com/mikro-orm/nestjs/issues/213) between one and multiple database connections.
28+
29+
To maintain a consistent JSON:API module configuration across different database adapters,
30+
I decided **not to add extra conditional checks** in the setup.
31+
32+
For everything to work correctly, @mikro-orm/nestjs should be integrated using the following module:
33+
👉 [MicroORM Database Module](https://github.com/klerick/nestjs-json-api/blob/master/libs/microorm-database/src/lib/micro-orm-database.module.ts).
34+
35+
```typescript
36+
import ormConfig from './config';
37+
38+
// need set contextName and registerRequestContext
39+
export const config: Options = {
40+
contextName: 'default',
41+
registerRequestContext: false,
42+
...ormConfig,
43+
};
44+
45+
@Module({
46+
imports: [MikroOrmModule.forRoot(config), MikroOrmModule.forMiddleware()],
47+
exports: [MikroOrmCoreModule],
48+
})
49+
export class MicroOrmDatabaseModule {}
50+
```
51+
52+
53+

0 commit comments

Comments
 (0)