On my projects, GORM wrote most of the SQL. We used it for almost everything and dropped down to a SQL library only for the complex queries. Over time GORM became the comfortable default, and the idea of writing raw SQL with sqlc and pgx made me uneasy.
The worry was specific. GORM has its own way of building queries, and I trusted its defaults to produce something reasonably efficient. When I write the SQL myself, nothing stops me from taking a strange route: joining through a table I don't need, because the result comes out the same. The rows are right, so nothing looks wrong, and the wasted work stays hidden.
sqlc will tell me if a query is invalid or a type doesn't match. It won't tell me the query is doing pointless work.
So I wrote a wasteful join on purpose and measured it. On small data it made no real difference. On 5 million rows it finished ahead of the clean query.…