News for hackers. Stuff that matters.
Re:Prisma – ORM for Node.js and TypeScript by abraxas on Wednesday April 21, 2021 @08:23AM (#26888662)
I think SQL gets a lot of undeserved praise that I’m having a difficult time understanding. The only impressive thing about SQL is its prevalence but that’s a pretty poor yardstick unless one thinks that an appeal to popularity is an indicator of quality.

Now let me count the ways in which SQL is bad:

- it composes poorly due to its unwieldy cobolesque syntax

- it is a leaky abstraction revealing a lot of underlying implementation tradeoffs

- it doesn’t properly implement Cobb’s relational model

- it is poorly standardized with a ton of proprietary extensions and alterations present in virtually every implementation

- it is still poorly supported by tools because the model metadata lacks any standard interface to make universal tooling possible

A lot of the praise for SQL is just bandwagon hopping and cargo cult behaviour or a lack of vision by most people of how things could be much better

Re:Prisma – ORM for Node.js and TypeScript by nicoburns on Wednesday April 21, 2021 @11:55AM (#26891311)
The great thing about SQL is the relational model. You typically can't compose parts of SQL queries easily from the programming language calling it, but SQL queries themselves compose incredibly flexibly. The result of of a SELECT query is itself a "relation" that can be queried just like a table.

I do wish someone would create a compile-to-sql language that adds variables and basic conditional support. I think T-SQL (SQL Server) has a lot of this, but it's missing in the Open Source world.

Re:Prisma – ORM for Node.js and TypeScript by dragonwriter on Wednesday April 21, 2021 @12:10PM (#26891542)
> I think T-SQL (SQL Server) has a lot of this, but it's missing in the Open Source world.

Every database with a procedural language based on SQL (Oracle PL/SQL, Postgres PL/pgSQL, etc.) has it, T-SQL just doesn’t segregate procedural and declarative code the way most engines do. Mostly, I think this is a negative for T-SQL, but sometimes segregation means there’s no way to do one-off procedural scripts without making and then calling a procedure; but Postgres, for example, since 9.0 has the DO statement for this use case (which supports any procedural language installed in the DB, but defaults to PL/pgSQL.)

Re:Prisma – ORM for Node.js and TypeScript by TheCoelacanth on Wednesday April 21, 2021 @04:18PM (#26894889)
I don't think SQL does compose well. Queries aren't first-class values in SQL.

I can write a query that queries the result of another query, but I can't store a query and then pass that somewhere to query from.

Re:Prisma – ORM for Node.js and TypeScript by pmontra on Wednesday April 21, 2021 @05:47PM (#26895867)
Maybe the WITH statement and CTEs can help you, if I understood correctly your complaint.

Check the example at the beginning of https://www.postgresql.org/docs/13/queries-with.html

Re:Prisma – ORM for Node.js and TypeScript by spion on Wednesday April 21, 2021 @08:55AM (#26889009)
What are you comparing it to? What is the better alternative?
Re:Prisma – ORM for Node.js and TypeScript by sonthonax on Wednesday April 21, 2021 @09:16AM (#26889248)
SQL isn't the only RDMS language, but it is the one with 50 years of incumbency.

Postgres before it was called 'PostgreSQL', used something called QUEL, which is quite a bit cleaner. There is also Microsoft's LINQ.

A typical programming language can express all that SQL can. In a way, an ORM is a cross-compiler from your programming language to SQL.

Re:Prisma – ORM for Node.js and TypeScript by vaughan on Wednesday April 21, 2021 @12:23PM (#26891743)
> A typical programming language can express all that SQL can. In a way, an ORM is a cross-compiler from your programming language to SQL.

SQL has always been a sort a magical, black-box in that you have very limited control over the query planner, and have to hint at it to do the right thing. (I guess `EXPLAIN` allows you to peak in the box a little)

I found [Apache Calcite](https://calcite.apache.org/docs/algebra.html) rather interesting. It provides the primitives that a DBMS is built from.

I would be interested to compare how PSQL is built in comparison. I would love a more layered/pluggable database that everyone can build off of. I think FoundationDB had this approach.

Re:Prisma – ORM for Node.js and TypeScript by spion on Wednesday April 21, 2021 @07:01PM (#26896475)
LINQ is pretty much a clone of SQL. Its nice, I agree, but do you think its materially different?

SQL could benefit from being language-integrated, yes. Very few languages can model relational algebra types though, if thats a thing you care about (it certainly is for me).

Re:Prisma – ORM for Node.js and TypeScript by htkien on Wednesday April 21, 2021 @09:33AM (#26889454)
An ORM API on the other hand is completely meaningless adhoc "whatever works". It doesn't have grounding in anything.
Re:Prisma – ORM for Node.js and TypeScript by abraxas on Wednesday April 21, 2021 @10:48AM (#26890355)
I'm making no statements about ORMs. I'm just picking apart the mindless "SQL is the bee's knees" mantra so prevalent on HN.
Re:Prisma – ORM for Node.js and TypeScript by vaughan on Wednesday April 21, 2021 @12:02PM (#26891425)
Would be interested in hearing what database and query language you think are better?
Re:Prisma – ORM for Node.js and TypeScript by abraxas on Wednesday April 21, 2021 @05:53PM (#26895924)
I think Datalog as implemented by Datomic has a much better syntax though I don't like Datomic per se.