I have one main db, in which each client's own db connection is stored. So every client works with 2 db: main and its own db, connection of which must be decided for each http call. How can I do this using flask-sqlalchemy extension, or may be purely in sqlalchemy?
You can handle multiple sessions in Flask-SQLalchemy:
engine = create_engine(DATABASE_URI)
db_session = scoped_session(sessionmaker(autocommit=False,
autoflush=False,
bind=engine))
db_session.query...()
and
engine2 = create_engine(DATABASE_URI2)
db_session2 = scoped_session(sessionmaker(autocommit=False,
autoflush=False,
bind=engine2))
db_session2.query2...()
sharing the same codebase.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With