Using multiple databases hustle #186
Replies: 4 comments 11 replies
-
It's hard to improve something when you don't say what is actually wrong. You are not supposed to use one instance without the context name in such setup. This sounds like you did not use the decorators property (since you need to put the context name in each ORM related decorator in that setup). The docs in the readme here should be correct, if you think otherwise, please provide a failing repro. |
Beta Was this translation helpful? Give feedback.
-
Hi. Thanks for your time. |
Beta Was this translation helpful? Give feedback.
-
Hi. Did you get to look into this? |
Beta Was this translation helpful? Give feedback.
-
Thanks a lot for taking the time to look into this. Still my initial request holds. More people will eventually call useFactory() with a parameter. And reading this
I understood that setting registerRequestContext=false and forMiddleware should be used
I will stick with only naming just one of the two since it is more convenient and it seems to work without the workarounds discused in #184 and without extra parameters definitions MikroOrmModule.forRootAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: (configService: ConfigService) => {
return {
autoLoadEntities: true,
driver: PostgreSqlDriver,
host: configService.get('EMPOWER_POSTGRES_HOST'),
port: +configService.get<number>('EMPOWER_POSTGRES_PORT', 5432),
user: configService.get('EMPOWER_POSTGRES_USER'),
password: configService.get('EMPOWER_POSTGRES_PASSWORD'),
dbName: configService.get('EMPOWER_POSTGRES_DB'),
extensions: [Migrator],
};
},
}),
MikroOrmModule.forRootAsync({
imports: [ConfigModule],
inject: [ConfigService],
contextName: 'empower-eclass',
useFactory: (configService: ConfigService) => {
return {
autoLoadEntities: true,
driver: MariaDbDriver,
host: configService.get('EMPOWER_MARIADB_HOST'),
port: +configService.get<number>('EMPOWER_MARIADB_PORT', 5432),
user: configService.get('EMPOWER_MARIADB_USER'),
password: configService.get('EMPOWER_MARIADB_PASSWORD'),
dbName: configService.get('EMPOWER_MARIADB_DB'),
};
},
}),
], |
Beta Was this translation helpful? Give feedback.
-
Hi!
I tried accessing two databases in my nestjs project using micro-orm (great by the way).
I spent a lot of time trying to figure out why using the documentation proposed way did not work for me.
When specifying a contextName for both database modules I was always getting weird errors about not having registered entities.
In the end after reading a post on how the same thing was implemented by nestjs/typeorm I tried to NOT set the contextName in one of the database modules and everything went smoothly after that.
If I am not missing something here I would suggest that this should be made clear in the docs that one of the database modules should be the default one (without a contextName defined) so that others are not affected as I was.
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions