Exposed icon indicating copy to clipboard operation
Exposed copied to clipboard

EntityHooks are not invoked when using DSL API

Open Nek-12 opened this issue 2 years ago • 1 comments

I'm using an EntityHook to sign up for changes in the database. When an entry is deleted, I want to create an entry in another table. My problem is that when I'm using a Table.deleteWhere() clause, EntityHook is not invoked. The only place where that entity hook is invoked, judging by the source code, is when the delete() method of the entity is called (Entity.kt line 249)

I want to listen to changes on any operation on a given table. How can I do this without using database triggers?

Nek-12 avatar Mar 19 '23 12:03 Nek-12

I could resolve this issue by creating special functions, but I guess this is not what you want, since EntityHook and StatementInterceptors have separated mechanics.

What I did was creating special functions that only should be used when making a CRUD operation, else, a normal transaction block would be used for selecting values. These functions had a lambda parameter called onDatabaseChanged, and, with the use of flows, emit the changes from the readers. It is quite complex so if you want to see the sample code just reply.

MJavoso avatar Sep 28 '24 01:09 MJavoso