Struggling with going full SharginGRDB in triggers #140
Answered
by
mbrandonw
sillygoose
asked this question in
Q&A
|
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. |
Answered by
mbrandonw
Aug 26, 2025
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. |
1 reply
Answer selected by
sillygoose
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @sillygoose, you can construct your
whenlike 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.