Replies: 2 comments 3 replies
-
I am wondering the same thing. I experimented with the approach from the gist below. But I keep getting this error:
Edit: I see now, Referenced gist: Posting full stacktrace in case any smart people come looking: Basically, get_engine is never called when the query is executed. Query is current_user from flask_login:
|
Beta Was this translation helpful? Give feedback.
-
All right, I figured out one way to to it. If anyone sees this i would love it if someone picked it apart and told me why this is a stupid way of doing it. The way i implemented it, you select a bind_key before each request (based on your own logic) and save it to in config variables I did not set a
Then in init.py you have to override both SQLalchemy (from flask-sqlalchemy) and the Session (also from flask-sqlalchemy). I did it like this:
Then, also in init.py file, instead of
use
Then, set up a way to select which bind_key to use. I used app.before_request, which will run before any request.
|
Beta Was this translation helpful? Give feedback.
-
I read the documentation but I did not find this use case.
If I have several databases to query, and they all have the same data model, how do I query by specifying the bind (bind_key) to which one to bind to?
Example:
settings/conf.py
models/init.py
models/user.py (remode model)
main.py
I tried this
db.session.configure(bind=db.engines['db1'])
but it doesn’t work.The real project is much more complicated than that.
Am I doing something wrong? Can anyone help me?
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions