-
Notifications
You must be signed in to change notification settings - Fork 150
-
We have a project using Gino, where a DB transaction is started on router layer (or similar) and feature layer code is called that does DB updates without knowing about the transaction. We now have a need to run code from the feature layer after the changes made are committed to the DB.
SQLAlchemy ORM has after_commit and similar hooks which can be used for this purpose, but I was unable to find any commit hooks in Gino. Does Gino have this kind of support? How would you suggest handling it?
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment 1 reply
-
I think you can listen for the commit
event: https://docs.sqlalchemy.org/en/13/core/events.html#sqlalchemy.events.ConnectionEvents.commit
Beta Was this translation helpful? Give feedback.
All reactions
-
The listens_for
requires an SQLAlchemy engine to be passed to it. What should I pass it?
I'm able to bind to the global engine:
from sqlalchemy.engine import Engine
async with db.transaction() as tx:
@event.listens_for(Engine, "commit")
def receive_commit(conn):
# do something
but this is triggered for any commit and they build up, the listening is never released. Is there a way to listen to the commit of the current transaction, and nothing later?
I have access to the db = gino.Gino()
object and have tried passing various properties but nothing else has worked at all. Thanks!
Beta Was this translation helpful? Give feedback.