Integrate with Sqlalchemy
See original GitHub issueHi.
I wanted to ask if you have any plans to make this work easily with Sqlalchemuy model? Let say we have a model which has a status
which needs to be updated every time we change the status using the machine. Of course we can implement this at the moment by using the trigger callbacks and update the state manually. I’m just wandering if you have such plans for the future.
Thx.
Issue Analytics
- State:
- Created 7 years ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
SQLAlchemy Documentation — SQLAlchemy 1.4 ...
SQLAlchemy 2.0 is functionally available as part of SQLAlchemy 1.4, and integrates Core and ORM working styles more closely than ever.
Read more >Flask Database Integration with SQLAlchemy - Section.io
In this article we will understand how to work with SQLAlchemy in a Flask web application. Storing data is an integral component of...
Read more >SQLAlchemy — Python Tutorial - Towards Data Science
We often encounter data as Relational Databases. To work with them we generally would need to write raw SQL queries, pass them to...
Read more >SQLAlchemy for Python | Sentry Documentation
The SQLAlchemy integration captures queries from SQLAlchemy as breadcrumbs. The integration is being tested with SQLAlchemy 1.2 or later. Python.
Read more >How to Use Flask-SQLAlchemy to Interact with Databases in a ...
You'll use SQLAlchemy with SQLite, although you can use it with other database engines too, such as PostgreSQL and MySQL. SQLite works well...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I found the @botzill’s answer super helpful! I’m now using that pattern throughout my app to drive model state changes off of state machine transitions. Thanks a ton!
For those who come after and are curious about exactly how/why this code works, I added a bit of commenting. Assume that on our core model,
Model
, we have a field which tracks the machine state, and call that fieldmodel_state
.The rest is fairly self-explanatory. After a state change, actually persist the changes to the database, etc. Thanks again @botzill!
OK, just a small update here. The examples above works OK when we initialize the model object ourself(and
__init__
is called). But when we make aquery
thensqlachemy
will initialize the model object itself and__init__
is not called(which mean that machine is not initialized). The solution I found so far is to use thesqlachemy
events, here is a complete example: