News for hackers. Stuff that matters.
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