Live data from Hacker News

Show HN: PgTyped – Typesafe SQL in TypeScript and Postgres

github.com

1–10 of 90 posts

Re: Show HN: PgTyped – Typesafe SQL in TypeScript and Postgres

#5
post #3

Is there anything like this for Rust or C++? I like the idea of code generation instead of doing the work at runtime (like in ORMs). This is like making your database schema the IDL spec.

https://github.com/launchbadge/sqlx perhaps

Also hugsql for clojure and pugsql for python.

Re: Show HN: PgTyped – Typesafe SQL in TypeScript and Postgres

#6
As a maintainer of a similar project[0], it's great to see another entry in this space.

sqlc currently has great support for Go and experimental support for Kotlin. I'm planning on adding TypeScript support in the future, so it's great to see that others in the TypeScript community find this workflow useful.

[0] https://github.com/kyleconroy/sqlc

Re: Show HN: PgTyped – Typesafe SQL in TypeScript and Postgres

#7
post #5
post #3

Is there anything like this for Rust or C++? I like the idea of code generation instead of doing the work at runtime (like in ORMs). This is like making your database schema the IDL spec.

https://github.com/launchbadge/sqlx perhaps Also hugsql for clojure and pugsql for python.

Sqlx looks nice! I had some ideas about porting pgtyped to rust and utilizing macros to do query type inference at build time, but was worried that such db-connected macros will slow down the build process. Nice to see that it worked out for sqlx.

Re: Show HN: PgTyped – Typesafe SQL in TypeScript and Postgres

#8
I came here to mention a similar approach, which last time I looked was a very compelling experiment[1], but its original author has actually built out a real library, Zapatos[2] which looks very very good.

[1]: https://github.com/jawj/mostly-ormless

[2]: https://jawj.github.io/zapatos/

Re: Show HN: PgTyped – Typesafe SQL in TypeScript and Postgres

#9
post #3

Is there anything like this for Rust or C++? I like the idea of code generation instead of doing the work at runtime (like in ORMs). This is like making your database schema the IDL spec.

There's Diesel[0] for Rust which is a full ORM. It's by Siân Griffin[1] who, as I understand it, is also behind a lot of how rail's ActiveRecord works.

0: https://diesel.rs/

1: https://twitter.com/sgrif

Re: Show HN: PgTyped – Typesafe SQL in TypeScript and Postgres

#10
Looks pretty cool. What I really want though is a library that let's me write plain SQL queries which are then mapped into nested objects in a smart way without too much manual work (I know Postgres can do JSON stuff, but the queries look pretty complicated for what little they actually do).

Say `SELECT * FROM user LEFT JOIN post ON user.id = post.id` would be mapped to `[{userId: 1, name: renke1, posts: [{postId: 2, title: "foo"]]`.

You probably need some kind of meta data to figure out how tables and thus objects relate to each other though.

Basically, I want to be able to leverage the full power of modern databases without being constrainted by typical ORM limitations. Also, I don't need features like lazy loading, sessions, caches and things like that.

A great advantage is that you can (provided you have some test data) easily test your queries while you develop a new feature (think IntelliJ IDEA where you can simply execute an SQL query on the fly).

Post reply on HN