sqlalchemy dynamic binding to model

Viewed 3864

I'm looking for a way binding models to different databases (schema is identical in all databases), for instance - separated by countries

class User():
    __tablename__ = 'user'

    id = Column(Integer, primary_key=True)
    name = Column(VARCHAR(255))
    age = Column(Integer)

This model is shared between multiple databases:

postgresql://postgres:@localhost/US

postgresql://postgres:@localhost/RU

Multiple binds is possible using flask: Flask-SQLAlchemy multiple databases and binds but bind key is hardcoded in the model http://flask-sqlalchemy.pocoo.org/2.1/binds/

Is there a way binding it dynamically to the model?

2 Answers
Related