One thing I've been exploring after GopherCon Africa 2026 is how Go developers work with databases. That's where I came across sqlc, a tool that makes writing database code in Go a little more interesting.
So, what does it actually do?
* What is sqlc?
*
When building an application, you might write SQL queries to fetch or insert data into a database. You then need Go code to execute those queries and work with the results.
Usually, this means writing some extra code to connect the two.
sqlc generates Go code from your SQL queries, allowing you to write the SQL yourself while getting generated Go functions with defined types.
In simple terms, you write the query, and sqlc helps handle the Go code around it.
How does it work?
Imagine we're building an application that stores information about farmers.
We might have a farmers table and want to retrieve a farmer using their ID.
First, we write the SQL query:
-- name: GetFarmer :one
SELECT id, name
FROM farmers
WHERE id = ?;
The comment tells sqlc…