Struggling with going full SharginGRDB in triggers #140
-
I have the following trigger that works but it bothers me I am using #sql() code. The concept is I have a table 'locations' that is referenced from the 'trips' and 'charges' tables and I want to delete a location when no trips or charges refer to it.
So I tried using
Is there a way do this cleanly without the #sql() or just get over it and move on? The desired code would be
but this isn't a QueryExpression so doesn't compile. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @sillygoose, you can construct your when: { old in
Charge
.where { $0.locationID.eq(old.locationID) }
.exists()
} This has the added benefit of being a little more efficient too. SQLite can just stop once it finds a row satisfying the condition rather than counting all rows that satisfy the condition. |
Beta Was this translation helpful? Give feedback.
Hi @sillygoose, you can construct your
when
like this:This has the added benefit of being a little more efficient too. SQLite can just stop once it finds a row satisfying the condition rather than counting all rows that satisfy the condition.