Dynamically setting DB connection


#1

Hey all,

Working on a multi-tenant application with each tenant having their own database. I’ve set up a tenant middleware.

My plan is to cache each tenant connection than when needed set the connection. Not sure if it would be best to do that in the middleware ( or if that’s even possible , kinda new to Adonis) or if it would be better to do it in the model through the connection property.

Thanks in advanced.


#2

Hey @Cmarenburg!

I would recommend you to read this issue https://github.com/adonisjs/adonis-lucid/issues/303, you may find some answers to your question.


#3

@Cmarenburg checkout my comment if it works https://github.com/adonisjs/adonis-lucid/issues/303#issuecomment-469593959