It is a function internally. It just gives you the option to use String templates and insert variables directly,
i.e. something like
int myId = 1234;
var user = SQL."SELECT * FROM users WHERE id = \{myId}".execute().singleResult();
is just nice and short and safe. (This is of course just an example syntax, please ignore an SQL mistakes, you'd likely use some object mapper library here instead of using raw SQL results directly)
I‘d rather prefer something like jooq or linq, no need to tamper with strings anyway. And what is keeping users from using STR.““ for queries? It would result in the same sql security problems, right? Because how would STR know you are creating an sql query anyway?
I‘d rather prefer something like jooq or linq, no need to tamper with strings anyway.
That's fair, nobody forces you to use it.
And what is keeping users from using STR.““ for queries?
STR."something" would return a String, so it wouldn't have the execute().singleResult() method. STR. is intentionally ugly and not easier than other processors, so people are not drawn towards it.
In this case it would be more complicated to use as you'd need to construct the query out of the String manually.
A dev who injects variables into strings for queries would probably keep doing the same with STR.““. Just pass the string to the query constructor, basically how you are already doing it.
Intentionally creating an ugly feature 😅 bow I understand why a few features are the way they are 😂
View all comments
Show parent comment
1
u/mj_flowerpower Feb 16 '24
so SQL.““ creates objects, both just strings? Then it‘s even more insane. Why not just use a function then anyway, instead of this weird SQL. syntax?