So I have multiple database. DB_US and DB_UK. They have the exact same structure but they hold data for different countries. I have an api with flask_restful. The endpoint accept a country to retrieve the data of this specific country.
My problem is I can't figure out how to select the database per request. I've read the bind method, but you have to specify a __bind_key per model and all my model are in both databases.
I've tried to initialize the database within the @before_request, but you can't call the init_db method (or any setup method) after the first request has been handled.
This is a particular case because the database are identical so it seems like it would make sense to have it in the same database, but it's part of a larger system and needs to be that way.
How could I select the database on a per request basis?