Your Question

How can I have GORM2 add after commit callbacks? I understand how to do it after an insert, update, delete or query. But I don't understand how to do it for a commit. I need this to push data into sockets

The document you expected this should be explained

https://gorm.io/docs/hooks.html https://stackoverflow.com/questions/70113632/is-there-any-after-commit-like-hook-for-gorm-golang https://github.com/go-gorm/gorm/issues/1951

I would like some advice or a link to documentation on how to do this.

Comment From: li-jin-gou

You need to add some func to gorm's callback and refer to https://gorm.io/docs/write_plugins.html.

Comment From: bioform

@li-jin-gou, those callbacks are explicitly attached to create/update/delete calls. Is there a way to attach the after commit hook to the db.Commit() call?

Comment From: bioform

It might be useful for scheduling a job in another DB. In my case, a new job must be sent to the Redis DB only after a successful Gorm transaction is committed.