Replies: 2 comments 3 replies
-
SQLBoiler does not know if the queries are performed in a transaction or not. The hooks are fired on the model itself after the insertion query is successful, which happens before the transaction is committed. If you want to get all |
Beta Was this translation helpful? Give feedback.
-
One more question, how will hooks behave if I have multiple workers sharing the same Postgres database? (I.E. when my service horizontally scales and has multiple instances) Will the hook only trigger the function for the worker that did the Insertion or Deletion, or will it trigger for all clients of that database? Essentially, I want all workers of my server to call the hook function if any one of them makes a change to the model. If SQLBoiler hooks won't work for this use-case, based on this stack overflow answer, using native Postgres triggers might be the correct approach here. |
Beta Was this translation helpful? Give feedback.
-
Hi,
I'm looking to use
AfterInsertHook
andAfterDeleteHook
to provide real-time updates to clients when specific rows get added or removed. If anymodels.A
row gets created or removed, then I want to send each client allmodels.A
that exists in the database.To do this, I use the hook as a trigger to get all
models.As
in the database.However, probably due to some kind of data race, the result of my query for all
model.As
is missing themodels.A
that was inserted. It's as if the hook is occurring before the transaction is committed, and even though I'm usingAfterInsertHook
it's getting the state of the DB prior to insertion.Any tips here? Is there a way to make the hook fire only after the transaction is committed to avoid this race? Thanks!
Beta Was this translation helpful? Give feedback.
All reactions