Live data from Hacker News

Show HN: PgTyped – Typesafe SQL in TypeScript and Postgres

github.com

11–20 of 90 posts

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

#11
I really like the unique approach of the annotated SQL files and can definitely see some use cases where it would be good to declutter the SQL from the code. For me personally, I'd be hesitant to add another build tool to my already bloated toolchain. Could create a special Babel-style "import" type that automatically transforms your code (JIT)? It could remove some of the friction in adoption (for Babel users at least).

Another one in a similar vein with strict typing and really nice SQL interpolation for Postgres: https://github.com/gajus/slonik

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

#12
post #2

Looks a little like the Typescript equivalent of Xo ( https://github.com/xo/xo ) for Go. Especially with Go, getting help with some initial scaffolding can be a huge timesaver. I'm assuming it's a similar gain for Typescript.

A better equivalent in Go is https://github.com/kyleconroy/sqlc

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

#13
post #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,…

Thanks! A grouping feature will definitely be useful, I have been thinking about a good way to add it to pgtyped.

Will grouping fields by tables they belong to good enough? Or is there some different grouping logic you have in mind?

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

#14
post #12
post #2

Looks a little like the Typescript equivalent of Xo ( https://github.com/xo/xo ) for Go. Especially with Go, getting help with some initial scaffolding can be a huge timesaver. I'm assuming it's a similar gain for Typescript.

A better equivalent in Go is https://github.com/kyleconroy/sqlc

thanks! I'll try this - one of my pet peeves with Xo is handling nullable types and more advanced types like JSONB required editing the generated code significantly to make it work. Hopefully sqlc solves that.

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

#15
post #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,…

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

#16
post #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,…

You never mentioned the language, so maybe Dapper? https://github.com/StackExchange/Dapper/

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

#17
post #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,…

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/

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

#18
post #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,…

You'd be constrained by whatever is trying to parse SQL queries to figure out what object structure to return instead.
Post reply on HN