The only substitute I'd accept is a quasiquoter that checked my SQL syntax for me at compile time.
The only substitute I'd accept is a quasiquoter that checked my SQL syntax for me at compile time.
Some of the additional query languages might be able to do it (they could certainly do chunks of what I said), but they'd still be pretty klunky about it since they bodge it on the side, and still don't compose anywhere near as well as they could or should.
Mind you, I'm not sure this library can do it either; SQL is also quite difficult to wrap around because of its structural deficiencies. Trying to hack away foundational issues at higher levels is always messy, error-prone, and still filled with the quirks that shine through.
Something like:
CREATE VIEW permitted_X AS
SELECT X.*
FROM X, user
WHERE X.user_id = user.user_id
AND (X.permission OR user.is_super);
You second example doesn't have enough info for me to see if it can be accomplished by a VIEW.Other abstraction mechanisms are user-defined functions.
[1] https://www.postgresql.org/docs/current/static/sql-createvie...
Some of these things are fixed up by the product-specific languages, but only some of these things.
Here's another example; using your product-specific language, can you create a table for me with a variable number and types of columns based on the parameters passed in? I don't know them all, but I bet it's hard in most or all of them. No credit if your product-specific language lets you bash a string together and then somehow execute it; I'm calling for everything to be done via first-class mechanisms. (Also, I'm not asking for whether this is a good idea; it is obviously a tricky thing of dubious use. But that should be a software engineering determination, not a language restriction.)
PREPARE stmt1 FROM 'SELECT X.* FROM ? X, user WHERE X.user_id = user.user_id AND (X.permission OR user.is_super)';
EXECUTE stmt1 USING 'yourtable';