Re:Show HN: PgTyped – Typesafe SQL in TypeScript and Postgres
by K0nserv on Monday May 25, 2020 @01:35PM
(#23303041)
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.
Re:Show HN: PgTyped – Typesafe SQL in TypeScript and Postgres
by status_quo69 on Monday May 25, 2020 @03:59PM
(#23304347)
Just to clarify a bit for other readers since I've worked with diesel for while, diesel isn't a "full" orm, as there are no real helpers provided to you outside of "we can map the result of a db query into a struct(s) that you specify" and some really nice guarantees for compile time queries. Other than that, your struct is a pretty dumb mapped representation and it's on the implementers of the application code to provide sugar for better access patterns. For people coming from something like active record, this is (in my opinion) closer to Arel than ActiveRecord, or closer to sqlalchemy core than sqlalchemy orm. As an example, you won't necessarily be able to do `MyStruct.join(OtherStruct)` and have it magically figure out how to query the database and map the results out of the box.
Re:Show HN: PgTyped – Typesafe SQL in TypeScript and Postgres
by status_quo69 on Monday May 25, 2020 @04:03PM
(#23304386)
Clarification: compile time query building, not querying. Due to inlining from the compiler, you can almost entirely construct the query at compile time and shave it down to a few string concatenations.
Re:Show HN: PgTyped – Typesafe SQL in TypeScript and Postgres
by aganame on Monday May 25, 2020 @01:04PM
(#23302823)
https://github.com/launchbadge/sqlx perhaps
Also hugsql for clojure and pugsql for python.
Re:Show HN: PgTyped – Typesafe SQL in TypeScript and Postgres
by alde on Monday May 25, 2020 @01:13PM
(#23302875)
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.
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.