You might be interested in looking at the Squirrel library for Gleam[1]. It kind of reverses the SQL problem in a very nice, elegant way I've found. It gets rid of some of the issues you are bringing up, which are quite valid.
[1] https://hexdocs.pm/squirrel/