Replies: 1 comment
-
Not interested in adding a global state, you can do this yourself trivially if you want, but it would only give you the global EM, which you cant really use for anything, you need contextual forks - and to get a contextual fork you can already use |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Is your feature request related to a problem? Please describe.
I'm trying to implement a multi-tenant project with nest and mikro.orm.
The solution was relatively easy using typeorm (see sample project here)
Using mikro-orm, I can't find equivalent methods to those :
import { Connection, createConnection, getConnection } from 'typeorm'; createConnection({name:tenantId ...}); // to create the connection. getConnection(tenantId); // to get a connection using its name
Within Nest, connections can be injected using @InjectEntityManager('db1'), which is very convenient if a project is using a few connections known ahead of time, but doesn't work as well if we have an unknown number of connections dynamically created at runtime according to a tenantId linked to every request.
Describe the solution you'd like
static methods to access the connections and their entityManagers.
something along the lines of :
import {createConnection, getConnection } from '@mikro-orm/core'
Describe alternatives you've considered
I considered using nest dynamic modules to create all the connections and export an array of providers, and then to import those in the services. This is probably going to work in the end, but the resulting code is way more complex than what could be achieved using my proposed change.
Beta Was this translation helpful? Give feedback.
All reactions