Skip to content

Does sqlmodel support ORM events as sqlalchemy does? #648

Answered by jlantz
khaliullin asked this question in Questions
Discussion options

You must be logged in to vote

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:

from sqlalchemy import event
from .models.job import Job

@event.listens_for(Job, "after_insert")
def handle_job_created(
    mapper,
    connection,
    target,
) -> Job:
    job = target
    ...

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.

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@vimeh
Comment options

Answer selected by khaliullin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
4 participants