Skip to content

Add example for Multi-Tenant #9

@pragmaticivan

Description

@pragmaticivan

Is your feature request related to a problem? Please describe.
Using multiple connections and binding connections to entities.

Describe the solution you'd like
For example:
A request is sent to an API and a middleware would introspect and select which tenant database connection.

I see that the .init the function would preload all the entities. Would that cause any problem to somehow load the entities on-demand based on different database connections?

Ex:

GET /foo (123)

  • load database connection for tenant 123.
  • When using entities, they would be associated with client 123 connection during the request.

I've found in the docs that it's possible to solve that by using const em = orm.em.fork(); or

app.use((req, res, next) => {
  RequestContext.create(orm.em, next);
});

For ref, I think having something like https://vincit.github.io/objection.js/recipes/multitenancy-using-multiple-databases.html in the docs would be very beneficial.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions