sqlc vs sqlx
Which should you use? A side-by-side look at what each one does, who it suits, what it costs, how hard it is to set up, and where each falls short.
Open source · MIT
Turns your SQL queries into type-safe code for Go, Python, Kotlin and more.
Open source · MIT
Go helper library that adds convenience features on top of the standard database/sql package.
The short answer
Choose sqlc if you need…
- Go developers who prefer writing plain SQL over using an ORM
- Teams that want database query mistakes caught when generating code rather than at runtime
- Projects using Python, Kotlin or TypeScript that want generated query code via the listed sqlc-gen plugins
Choose sqlx if you need…
- Go developers who already use database/sql and want less boilerplate when reading rows
- Projects that want named query parameters such as :first_name
- Code that maps query results onto Go structs
- Teams that need batch inserts from slices of structs or maps
Side-by-side
| sqlc | sqlx | |
|---|---|---|
| Type | Dev tool | Library |
| Price | Free and open source | Free and open source |
| Licence | MIT | MIT |
| GitHub stars | 18.4k | 17.7k |
| Setup difficulty | Intermediate | Intermediate |
| How you get it | See the README | Install with a package manager |
| Main language | Go | Go |
| Last code update | 4 days ago | 2 years ago |
What each one is
sqlc
sqlc is a tool that reads the SQL queries you write and generates code in your programming language with type-safe functions for running them. You write the SQL yourself, run sqlc, and then call the generated functions from your application. The README says it works with PostgreSQL, MySQL and SQLite, though the list of supported databases is not shown in the excerpt provided.
sqlx
sqlx is a Go library that extends the standard database/sql package. Its database types keep the same interfaces as the originals, so existing code can be adopted gradually. It can map query rows into structs, maps, and slices, supports named parameters, and offers Get and Select helpers to load a single result or a list directly.
Best for
sqlc
- Go developers who prefer writing plain SQL over using an ORM
- Teams that want database query mistakes caught when generating code rather than at runtime
- Projects using Python, Kotlin or TypeScript that want generated query code via the listed sqlc-gen plugins
sqlx
- Go developers who already use database/sql and want less boilerplate when reading rows
- Projects that want named query parameters such as :first_name
- Code that maps query results onto Go structs
- Teams that need batch inserts from slices of structs or maps
Strengths
sqlc
- Queries stay in readable SQL that you control directly
- Generated code gives type-safe interfaces to your queries
- Supports multiple output languages through official and plugin generators
sqlx
- Keeps the standard database/sql interfaces, so it fits into existing codebases
- Reduces repetitive row-scanning code through struct and slice mapping
- Has been around long enough to have wide adoption, with about 17.7k GitHub stars
Not ideal for
sqlc
- People who want to avoid writing SQL entirely, since the workflow starts with hand-written queries
- Projects needing a language not covered by the listed generators, unless they build or find a community plugin, because the README only says more languages can be added via plugins
sqlx
- Developers who want a full ORM with models, migrations, and relationship handling, since the README describes only query and mapping extensions
- Projects not written in Go
- Complex queries where column names are ambiguous, because the README warns that struct or map mapping can be unclear in those cases
Trade-offs
sqlc
- You must maintain the SQL and regenerate code whenever queries or schema change
- The excerpt does not show the full list of supported databases or language features, so check the documentation before adopting it
sqlx
- The README notes that duplicate or ambiguous column names can make struct and map mapping unclear, so queries need explicit AS aliases
- Behavior of multi-statement Exec differs between database drivers, according to the README
- Compatibility is promised only for the two most recent Go versions
Getting started
sqlc
Clone the repository
git clone https://github.com/sqlc-dev/sqlcFrequently asked questions
What is the difference between sqlc and sqlx?
sqlc: Turns your SQL queries into type-safe code for Go, Python, Kotlin and more. sqlx: Go helper library that adds convenience features on top of the standard database/sql package. sqlc suits go developers who prefer writing plain sql over using an orm, while sqlx suits go developers who already use database/sql and want less boilerplate when reading rows.
Are sqlc and sqlx free?
sqlc: Free and open source. sqlx: Free and open source.
Is sqlc or sqlx more popular?
sqlc has more GitHub stars (18.4k) than sqlx (17.7k). Popularity isn't the same as fit — check which one matches your use case above.
What are other alternatives to sqlc and sqlx?
Other options people compare them with include GORM, GraphQL Code Generator.
Keep comparing
Built from our catalogue entries for both products: open-source details come from each project's README (AI-assisted, refreshed weekly) and GitHub data; AI-tool details are editorial. Spotted something wrong? Let us know from either product's page.