-
-
Notifications
You must be signed in to change notification settings - Fork 899
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Writing re-usable, decoupled models (multi-app architecture) #648
Comments
Personally I just use Flask-SQLAlchemy everywhere. Even if it's not a webapp, you can simply wrap your code with a flask app context - all you need is to call |
See #250 for previous work on this and https://stackoverflow.com/a/33127999/400617 for an example of what ThiefMaster is talking about. |
Hi @davidism I am really sorry but unfortunately, neither of those two links answer my question. Example given in the end of #250 discussion does not work with a multi-database setup. Specifically, models do not bind to the correct engine using with Second link and solution provided by ThiefMaster allows to use models across multiple flask applications but it does not solve for non-flask environment. Shipping flask and flask-sqlalchemy with non-flask applications is barely a workaround and does not scale. Imagine the following scenario - you have a non-flask codebase, developed by another team using SQLAlchemy, and you are developing a simple Flask-based frontend for it. Asking them to couple their architecture to flask-sqlalchemy and flask seems like a really bad idea. |
Please use Stack Overflow for questions about your own code. This tracker is for issues related to the project itself. Be sure to include a minimal, complete, and verifiable example. |
I am writing a complex web application that consists of a multiple flask apps, as well as non-flask Python apps (internal scheduler, etc).
I need to write models that I can re-use across multiple Flask apps, as well as non-flask python code using pure SA. However, I don't want to lose any benefits that Flask-SQLAlchemy gives you (when possible).
My first approach was to use declarative_base and it somewhat works:
However, multi-database binds don't seem to work properly. When I run
It ignores the bind/bind key and runs it against the default database (and fails).
What should be correct approach here?
The text was updated successfully, but these errors were encountered: