Live data from Hacker News

Sqlc: Compile SQL to type-safe code

sqlc.dev

51–60 of 109 posts

Re: Sqlc: Compile SQL to type-safe code

#51
Surprised nobody has mentioned “Kysely” (https://kysely.dev).

It is a query builder (not an ORM), that (ab)-uses the Typescript type system to give you full type safety, intellisense, autocomplete etc.

Crucially it doesn’t require any build/compile step for your queries which is fantastic.

Re: Sqlc: Compile SQL to type-safe code

#52
post #47
post #44

There was a saying that before learning postgres in depth, the db is just a dumb store of data for devs, once you spend time to learn the tools it provides though, most applications just look like a very thin layer on top of the sql. There is so much more to rdbms (especially pg) than just joins - common table expressions, window functions, various views, let alone all the extensibility - extensions, custom types, ev…

This is what jOOQ does. Best SQL library I've ever used. https://www.jooq.org/

[deleted]

Re: Sqlc: Compile SQL to type-safe code

#53
post #44

There was a saying that before learning postgres in depth, the db is just a dumb store of data for devs, once you spend time to learn the tools it provides though, most applications just look like a very thin layer on top of the sql. There is so much more to rdbms (especially pg) than just joins - common table expressions, window functions, various views, let alone all the extensibility - extensions, custom types, ev…

It would be great to have some sort of sql string to type parsing as some sort of plugin to TypeScript.

Didn’t use myself, but AFAIK slonik library is doing what you’ve described: https://github.com/gajus/slonik

Re: Sqlc: Compile SQL to type-safe code

#54
post #47
post #44

There was a saying that before learning postgres in depth, the db is just a dumb store of data for devs, once you spend time to learn the tools it provides though, most applications just look like a very thin layer on top of the sql. There is so much more to rdbms (especially pg) than just joins - common table expressions, window functions, various views, let alone all the extensibility - extensions, custom types, ev…

This is what jOOQ does. Best SQL library I've ever used. https://www.jooq.org/

We use jOOQ, and love it. But sqlc also makes nice trade offs. I see it does Kotlin generation: if this lib was around when we picked jOOQ, I's certainly had considered it.

Differences:

* jOOQ is an eDSL with an optional schema-to-classes generator

* you write jOOQ queries in Java (or Kotlin as we do)

* there's quite a bit of type-safety added when using the generator: the schema needs to be match the queries you write or you get compile errors

* jOOQ queries are built are run time adding a little overhead that sqlc does not

* writing jOOQ is very close writing SQL (a very thin abstraction), sqlc is "just SQL" it seems

Re: Sqlc: Compile SQL to type-safe code

#55
post #51

Surprised nobody has mentioned “Kysely” ( https://kysely.dev ). It is a query builder (not an ORM), that (ab)-uses the Typescript type system to give you full type safety, intellisense, autocomplete etc. Crucially it doesn’t require any build/compile step for your queries which is fantastic.

I had a look. It says it's type safe but I see strings everywhere. It seems the IDE can autocomplete the strings, but does that count as type safety nowadays?

(How does the IDE do the autocomplete on strings? Will the compiler also catch "bad strings"?)

Otherwise it looks much like jOOQ but without the "jOOQ generator" (which adds most of the type safety).

Re: Sqlc: Compile SQL to type-safe code

#56
post #54
post #47

Earlier quoted context omitted.

This is what jOOQ does. Best SQL library I've ever used. https://www.jooq.org/

We use jOOQ, and love it. But sqlc also makes nice trade offs. I see it does Kotlin generation: if this lib was around when we picked jOOQ, I's certainly had considered it. Differences: * jOOQ is an eDSL with an optional schema-to-classes generator * you write jOOQ queries in Java (or Kotlin as we do) * there's quite a bit of type-safety added when using the generator: the schema needs to be match the queries you wri…

Yep sqlc is more akin to Kotlin's SQLDelight https://github.com/cashapp/sqldelight

Re: Sqlc: Compile SQL to type-safe code

#57
post #44

There was a saying that before learning postgres in depth, the db is just a dumb store of data for devs, once you spend time to learn the tools it provides though, most applications just look like a very thin layer on top of the sql. There is so much more to rdbms (especially pg) than just joins - common table expressions, window functions, various views, let alone all the extensibility - extensions, custom types, ev…

I keep hearing about how powerful pg is. It would be great to see an example application that uses all it's features.

Re: Sqlc: Compile SQL to type-safe code

#58
post #44

There was a saying that before learning postgres in depth, the db is just a dumb store of data for devs, once you spend time to learn the tools it provides though, most applications just look like a very thin layer on top of the sql. There is so much more to rdbms (especially pg) than just joins - common table expressions, window functions, various views, let alone all the extensibility - extensions, custom types, ev…

If you're into JS there was an query builder posted a few days back that was fairly closely mapped to SQL, it in turn was inspired by Linq (and EFCore behind it).

I didn't look forward to working with C# initially but Linq has been a fresh air since your statements more or less map 1:1 to SQL and probably quite overlooked because of "Microsoft"(and that Linq with old EF could have nasty surprises).

What people don't know/realize is that because Linq expressions in C# are left "uncompiled" they can be passed to the SQL layers and converted to idiomatic SQL, so you have all the typesafety of C# and regular C# code but get SQL code that is executed on the server (there is some minor impedance mismatch but it's minor enough and mainly with strings).

https://news.ycombinator.com/item?id=41455719

Re: Sqlc: Compile SQL to type-safe code

#59
post #5

Migrated from GORM to sqlc. We like the code generation approach with the simplistic abstractions. https://github.com/helpwave/services/tree/main/services/task...

ORMs make the easy things slightly more easy and the complex things impossible, so you still need SQL-as-strings or other technology (like sqlc).

Imho ORMs are not worth it. Too much to learn (often through nasty surprises) for too little benefit.

Re: Sqlc: Compile SQL to type-safe code

#60
post #56
post #54

Earlier quoted context omitted.

We use jOOQ, and love it. But sqlc also makes nice trade offs. I see it does Kotlin generation: if this lib was around when we picked jOOQ, I's certainly had considered it. Differences: * jOOQ is an eDSL with an optional schema-to-classes generator * you write jOOQ queries in Java (or Kotlin as we do) * there's quite a bit of type-safety added when using the generator: the schema needs to be match the queries you wri…

Yep sqlc is more akin to Kotlin's SQLDelight https://github.com/cashapp/sqldelight

That's a really nice project indeed. We looked at it I remember, when we pciked jOOQ, but it was too new to bet the farm on back then. It progressed really nicely.
Post reply on HN