by galaxyLogic · 3y ago · 0 comments
The documentation for EdgeDb goes into some detail about that and shows an alternative better language for data-queries.
https://www.edgedb.com/showcase/edgeql
To understand why SQL is bad, you must first be shown something better, and EdgeDb seems to be such better more composable language.
The syntax example on the PRQL homepage
from invoices
filter invoice_date >= @1970-01-16
derive [
transaction_fees = 0.8,
income = total - transaction_fees
]
filter income > 1
group customer_id (
aggregate [
average total,
sum_income = sum income,
ct = count,
]
)
sort [-sum_income]
take 10
join c=customers [==customer_id]
derive name = f"{c.last_name}, {c.first_name}"
select [
c.customer_id, name, sum_income
]
Trailing commas, select at the bottom, filter is both a WHERE and HAVING replacement, easy filtering of created columns, etcThe notion that SQL is not composable is either a lie or simply repeated by folks with only a cursory knowledge of SQL from 20 years ago.
Views, set-returning functions, CTEs, and more: all examples of composability in SQL.
Then of course there's the issue of security where folks tend to put all of their access constraints into their middleware AFTER the data has already been returned over the wire in bulk. Take a moment to consider role-based access control and row-level security policies. Instead of trying to track down every possible spot where a JOIN could have crept in past the code reviews (you code review your DDL and DML, right?), you set your GRANTs, REVOKEs, and POLICYs at the points in your data model that need them; restricted data never makes it into intermediate result sets let alone the final result set and the wire.
Don't misunderstand me. GRANT, REVOKE, and POLICY can be a real PITA, but that's because *security* is a PITA, not the SQL syntax to enforce it. Anyone who tells you their app solves your data security problems in the app tier with a point and click is a lying salesman.
https://www.datasqrl.com/blog/sqrl-high-level-data-language-...
For the record, I make heavy use of SQL because relational databases are awesome and SQL is the least bad option I've found so far. But the many shortcomings of SQL still annoy me.
I thought the same until a few weeks ago. Then we used the WITH operator for pre-processing and giving things human-readable names.
That helped us manage complexity. The final SELECT statement was very easy to reason about.
Not sure if this is a best (or worst) practice but it helped us ship it.