Beyond sqlc: teaching AI to generate repositories and integration tests in Go

Using sqlc (a SQL compiler) in Go is great for generating type-safe database access. However, using the structs generated by sqlc directly in the business logic layer would tightly couple the domain to the database schema. To keep things flexible, a repository layer is needed to map between generated structs and domain models. But writing this mapping by hand quickly becomes repetitive.

The talk begins with a review of the evolution of working with Postgres in Go: from the standard library’s database/sql, through Squirrel + sqlx, pgx driver and API, to modern SQL-first approaches with sqlc. It then introduces an AI-powered generator that creates repository layers based on provided interfaces and domain models, leveraging sqlc-generated queries. The generator, playfully named sqlc++, is powered by Claude Code with a custom command and uses a GitHub project with a reference implementation as an example. This reference-based approach reduces LLM hallucinations and ensures consistent code style.

This approach makes it easier to bootstrap a new repository: in addition to what sqlc already requires (SQL schema and queries), one has to define domain models and a repository interface. From there, the sqlc++ generator produces the repository implementation and integration tests, ensuring consistency and avoiding repetitive boilerplate.

LEVEL: Intermediate
Place
Michelangelo
Length
45 min
When
October 7th, 2025
09:30

Abstract

Using sqlc in Go is great for generating type-safe database access — but using its generated models / records directly in your service layer ties your domain to the database structure. To keep things flexible, a repository layer is still needed to handle mapping and transactions — but writing that by hand gets repetitive fast.

In this talk, I’ll show how I built a custom Go generator that uses AI to create repositories and integration tests on top of sqlc, based on reference implementation I provide. Unlike Copilot Chat, there’s no copy-pasting or re-explaining — the tool understands the structure I want and generates consistent code automatically.

This makes it easy to bootstrap a new project: define your SQL schema, write your queries, repository interface, run sqlc, and let the generator build the repository implementation and integration tests for it.

GoLab is a conference made by Develer.
Develer is a company based in Campi Bisenzio, near Florence. Our motto is : "Technology to give life to your products". We produce hardware and software to create exceptional products and to improve industrial processes and people's well being.
In Develer we have passion for the new technologies and we offer our clients effective solutions that are also efficient, simple and safe for the end users. We also believe in a friendly and welcoming environment where anybody can give their contribution. This passion and this vision are what we've been driven to organize our conference "made by developers for developers".


Subscribe to our newsletter

We hate spam just as much as you do, which is why we promise to only send you relevant communications. We respect your privacy and will never share your information with third parties.
©2025 GoLab | The international conference on Go in Florence-Design & devCantiere Creativo-Made withDatoCMS