Hacker News new | ask | show | jobs
by masklinn 4737 days ago
> Why try and wrap it up, and pretend that you are writing Java, when you're still writing SQL?

That's not what query builders (/expression languages) do. They just express the SQL in the host language to allow for compositions and the like.

Because like it or not, expressing SQL as a string is a pain in the ass to compose, you can't easily build a query incrementally.

With a query builder, you can. You're still writing SQL, it's not an object layer/ORM and it has (should have) a fairly direct mapping to SQL. You're just writing SQL in a way which fits better in the host languages.

Oh, it can also provide some measure of database-independence by having database-specific backend take care to handle specific incompatibilities between databases.

For instance for string concatenation[0] the standard is `||` which works in SQLite, Postgres and Oracle, MSSQL uses `+` instead of `||` and in MySQL `||` is the boolean OR unless you've activated a specific sql mode so you've got no choice but to use CONCAT (you could accept a performance hit and use CONCAT everywhere, except Oracle only supports an arity of 2 and SQLite doesn't support this function at all).

That's the kind of stuff a builder can handle for you under the hood, providing much improved cross-platform compatibility.

[0] http://troels.arvin.dk/db/rdbms/#functions-concat