What does HackerNews think of sqlc?

Generate type-safe code from SQL

Language: Go

#7 in Go
#1 in Kotlin
#3 in MySQL
#3 in PostgreSQL
#10 in Python
#4 in SQL
I was interested in looking up sqlc for python but it seems to be for go? Is there a different version than this? https://github.com/kyleconroy/sqlc
This is pretty much the idea behind sqlc, with some extra steps of course. You write your SQL queries in file, and it generates type safe bolierplate for you.

https://github.com/kyleconroy/sqlc

As the post you're replying to describes, magic is antithetical to Go idioms. An ORM is basically database-as-magic, every ORM in Go is just a nightmare.

Something like sqlc[0] is leagues better than any ORM in terms of simplicity, complexity and maintainability.

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

If you're using postgres, I'm a major fan of the anti-ORM (ROM?) that is sqlc. Nothing I've used comes in Go close in productivity or safety (and ability to write proper queries but use them very simply, and stay up-to-date without too much extra toil). Last I checked they're also working on adding sqlite support.

https://github.com/kyleconroy/sqlc/

FWIW for SQL, sqlc[1] is probably the nicest SQL layer I've used in any language.

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

If you are into Golang, also well worth checking out sqlc. It parses your migrations to generate typed structs and query funcs

https://github.com/kyleconroy/sqlc

Doing it the other way around makes more sense, i.e. write SQL to generate code. See https://github.com/kyleconroy/sqlc, why aren't more people following this approach?
I've enjoyed using https://github.com/kyleconroy/sqlc on a couple of projects. Give it your schema and queries, get type-safe interfaces in return. It's a happy medium for me between all-in ORM and raw SQL.
You might like the approach I took with pggen[1] which was inspired by sqlc[2]. You write a SQL query in regular SQL and the tool generates a type-safe Go querier struct with a method for each query.

The primary benefit of pggen and sqlc is that you don't need a different query model; it's just SQL and the tools automate the mapping between database rows and Go structs.

[1]: https://github.com/jschaf/pggen

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

SQLC could be a good fit. It generates type-safe Go code from SQL.

https://github.com/kyleconroy/sqlc

Tried sqlx a few weeks ago. I personally didn't like it. I come from a Hibernate/JVM background. Writing a data access layer with that much boilerplate isn't something I consider to be practical in today's fast paced environments.

After sqlx, I gave sqlc (https://github.com/kyleconroy/sqlc) a try and I found it to be much more painless than any other database solution (for PostgreSQL) for Golang.

Edit: sqlc is an inversed solution. Instead of generating SQL queries using Golang, you write annotated SQL queries and sqlc generates Golang source from them.

Around the ORM choice, I would stay with raw SQL Queries and use sqlc with to generate the boilerplate (structs and the repository itself). I have been using it and it is amazing. Only issue it only supports postgres, although it has beta support for other DBs.

https://github.com/kyleconroy/sqlc

SQLx is good for simple read queries, but iirc for write operations you still need to map things manually and reads with JOINs are a bit tricky. Gorm might be good for simple CRUD applications, but it's magic has a performance cost.

The sqlc lib "generates fully type-safe idiomatic Go code from SQL". It makes sense to generate code from SQL and not the other way around. https://github.com/kyleconroy/sqlc
This is similar to sqlc for Golang: https://github.com/kyleconroy/sqlc

If you're looking for the ability to generate type-safe SQL – given you write SQL correctly – this project is pretty good.

Aalso a fan of SQLBoiler (https://github.com/volatiletech/sqlboiler) for Golang, for simple type safety:

`models.Accounts(models.AccountWhere.ID.EQ(id)).One(ctx, db)`.

Though SQLBoiler breaks with left joins, as it auto-generates your structs and maps results 1-1 with table definitions. In this case you have to custom type something, either using sqlc or squirrel.

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

I maintain an open source project with ~2k stars (https://github.com/kyleconroy/sqlc). There’s a large list of bug reports and feature requests, but since I don’t work on it full time, I’ve gotten really good at saying “No” and “I’m sorry”.
SQL.

I'm writing a compiler for SQL that parses DDL (CREATE TABLE, etc.) and queries and outputs type-safe Go. It currently supports PostgreSQL, but the plan is to support more engines and more output programming languages.

https://github.com/kyleconroy/sqlc

I'm working on a tool that compiles SQL queries into type-safe code. It's called sqlc and it already works really well: https://sqlc.dev

Go and PostgreSQL are currently supported, with Kotlin and MySQL support on the way.

https://github.com/kyleconroy/sqlc

Very cool! I maintain a similar tool: sqlc https://github.com/kyleconroy/sqlc

In addition to catching SQL errors, it generates type-safe Go wrapping code. Right now it supports PostgreSQL and MySQL.

I’m (obviously) a huge fan of the SQL first approach and hope more people adopt it for their own projects.

I wasn't happy with the current database access packages (https://github.com/jmoiron/sqlx, https://gorm.io), so I wrote my own for PostgreSQL. It takes existing queries and generates type-safe Go methods (https://github.com/kyleconroy/sqlc). I enjoy using it and thought others might too.

As for migrations, I've had success with https://github.com/pressly/goose. It's lightweight and is also just SQL.

If you use Go and PostgreSQL, I’ve been working on a tool to help you “just use SQL” called sqlc[0]. It generates methods and structs for your queries, automatically. It’s made a dramatic difference in my day-to-day workflow.

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