News for hackers. Stuff that matters.
Re:Show HN: PgTyped – Typesafe SQL in TypeScript and Postgres by goliatone on Monday May 25, 2020 @02:20PM (#23303412)
You should check objection.js[1] as I think it would get you what you describe and probably more. It is a relational query builder built on top of knex, which is a query builder.

[1] https://vincit.github.io/objection.js/

Re:Show HN: PgTyped – Typesafe SQL in TypeScript and Postgres by mceachen on Monday May 25, 2020 @03:19PM (#23303987)
I wrote the original typescript bindings for objection. One of the library authors is a contributor to knex.js, which objection uses for query building. Both are quite nice.

With either library, you aren't writing naked SQL, but something like `query.where("updated_at", ">", Date.now())`. Tsc comes into play when you send typed objects into your .where, .insert, ... methods and what you get back from the query.

It's close enough to SQL that you don't lose expressiveness, you're not behind walls of magick due to orm, and you don't have to worry about Bobby Droptables.

Re:Show HN: PgTyped – Typesafe SQL in TypeScript and Postgres by renke1 on Monday May 25, 2020 @02:28PM (#23303486)
Thanks, I'll check it out. But on first glance it doesn't seem to let me write actual SQL queries. Also, it doesn't seem to be typesafe, or is it?
Re:Show HN: PgTyped – Typesafe SQL in TypeScript and Postgres by chrischen on Monday May 25, 2020 @02:56PM (#23303768)
It says it has typescript support.
Re:Show HN: PgTyped – Typesafe SQL in TypeScript and Postgres by renke1 on Monday May 25, 2020 @03:21PM (#23303998)
I didn't check those typings, but I don't think the model itself is type safe from the looks of it.
Re:Show HN: PgTyped – Typesafe SQL in TypeScript and Postgres by mceachen on Monday May 25, 2020 @03:27PM (#23304069)
It is. See my ggp reply.