Hello @danurigom I hope you are well. I hadn’t checked the “Ray” forum for a long time and hadn’t seen your question. In my case, I managed to solve the problem of several database connections in both Vapor 3 and Vapor 4. In Vapor 3 I had to overwrite several classes of Vapor, however it is no longer necessary to go into details because we currently have Vapor 4. I’m currently finishing the migration to Vapor 4 ( this update broke a lot of code). Vapor 4 is basically a bit more flexible when it comes to allowing it to make connections to different databases due to invocations using Fluent 4 does not use the “Request” object but needs a “Database” object which makes the implementation a bit easier. However, Vapor 4 (in my opinion) still has some problems regarding the BD’s configuration, however I managed to solve in a simple way:
- The connections to the databases must be declared within the project since Vapor needs to load them when deploying the backend, for example:
- Generate a function to intercept the requests made to the backend and using a header I determine the database that I am going to use:
Basically I get the request header and depending on that this function decides which DB connection to use.
- Finally, a request would be as follows:
I always get the connection to the DB and then I pass it on to the query I am going to make.
In short, this would be my solution. If you still have problems, I hope you can get an idea.
NOTE: I’m sorry for my English .