Does sqlmodel support ORM events as sqlalchemy does? #648
Unanswered
khaliullin
asked this question in
Questions
Replies: 2 comments 1 reply
-
I'd guess it's possible, and that the answer is there, but I could not grasp the metamodel programming enough to get it. https://github.com/tiangolo/sqlmodel/blob/main/sqlmodel/main.py#L209 |
Beta Was this translation helpful? Give feedback.
0 replies
-
I'm not sure if something changed or perhaps I'm just targeting a different event at the model level vs the table level, but this code is working for me to trigger events after_insert:
I previously tried to post code that I thought was working but in fact wasn't. I got tripped up on the jump from my async endpoints to synchronous listener function. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
First Check
Commit to Help
Example Code
Description
I am trying to create audit table for my application. I need to log all changes (at least CREATE, UPDATE actions) to AuditLog database table, to keep changes history of every record with user, action and fields information. Could not find any examples in SQLModel documentation, but SQLAlchemy provides ORM Events to implement this. Is it possible to do with SQLModel tables?
this code raises error:
sqlalchemy.exc.InvalidRequestError: No such event 'after_commit' for target '<class 'app.models.Task'>'
I need to get sqlalchemy class for sqlmodel Task class. Is it possible to do? If yes, how to get such class for common model to avoid code duplication?
Operating System
macOS
Operating System Details
No response
SQLModel Version
0.0.8
Python Version
3.11.4
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions