I have the databases foobar_pt, foobar_br, foobar_mx and so on, they all have the same model.
On the other hand, I created one blueprint using the (same) model, and I want to do something like:
class Product(db.Model):
__tablename__ = 'product'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(10), nullable=False)
api = Blueprint('api', __name__)
@api.route('/products')
def product_get():
...
result = Product.all()
...
return jsonify(result)
and here is the problem:
# this blueprint should use the foobar_pt DB
app.register_blueprint(api, url_prefix='/pt')
# this blueprint should use the foobar_br DB
app.register_blueprint(api, url_prefix='/br')
# this blueprint should use the foobar_mx DB
app.register_blueprint(api, url_prefix='/mx')
...
[more countries]
the idea is to have an API like:
# get the products from PT
https://www.example.com/pt/products
# get the products from BR
https://www.example.com/br/products
# get the products from MX
https://www.example.com/mx/products
...
[more countries]
the model is exactly the same, the only thing that changes is the database name
Is there any way to do that?