Set dynamic database connection

Hello , is it possible to set dynamic database connection on run time? I have Laravel application , I created a middleware where it gets subdomain and connects clients to its database , so its subdomain based multitenant application. I want to make remake my application with Adonis js , how can I achieve similar approach? I have 40 clients with 40 databases (each client has 80 to 400 concurrent users online) , my goal is serve api by sub domain with single adonis instance. Thank you in advance for your help.

Update: I checked documentation and saw Multiple Connections section , is it what I am looking for? If I define 40 database connections (all databases in same host, same schema ,same user name , same password , only database names are different) is it cause performance issues?

Update 2: I keep checking documentation , lucid#_connection My question is , can I select dynamic connection with lucid ? maybe pass a variable to connection function?

Update 3 : I managed to choose connection dynamically following this Multiple Connections section.
Now my question is , is it bad to have 40 database connections?

Hey @Majoris! :wave:

This is currently not doable in Adonis 4.X.

Good news, this feature is already implemented in Adonis 5 that should be release near the end of the year.

More information about this:

Keeping each connection in there takes little bit RAM from Node server.
But if all those 40 connections start to hit database hard and all 40 databases are on the same server then database might not be really happy.

Test it if database handles it then it’s all good. I really doubt there will be issues on Node / Adonis side