Overview
Bun is a Go ORM developed since 2021 by Uptrace, with most commits from one lead developer. It sits on top of database/sql, so any compatible driver works, and ships dialects for PostgreSQL, MySQL/MariaDB, SQL Server, SQLite and Oracle.
Queries are built with db.NewSelect(), NewInsert() and similar methods that expose SQL concepts directly: ColumnExpr, TableExpr, With for CTEs, and raw expressions where needed. Models use struct tags for tables, columns and relations (has-one, belongs-to, has-many, many-to-many), and results can be scanned into structs, maps, scalars or slices.
Bun includes a migration system that runs Go or SQL migration files, fixtures for test data, soft deletes, query hooks and OpenTelemetry instrumentation. It does not generate migrations from model changes.
Bun suits developers who find GORM too magical but do not want to write every scan by hand. Because it builds on database/sql, you can mix Bun queries with plain SQL and existing drivers, and the query hooks make it easy to log or trace every statement during development.
Pricing and plans
| Plan | Price | What you get |
|---|---|---|
| Bun | $0 | BSD 2-Clause licence |
What it does
- SQL-shaped query builder
- Select, insert, update, delete, CTEs, subqueries and raw expressions that map closely to the generated SQL.
- Relations
- Has-one, belongs-to, has-many and many-to-many relations declared with struct tags.
- Flexible scanning
- Scan results into structs, maps, scalars or slices.
- Migrations and fixtures
- Run Go or SQL migrations and load fixtures for tests.
- Observability
- Query hooks and OpenTelemetry support for tracing database calls.
Strengths and limitations
Strengths
- Close to SQL, so the generated queries are predictable
- Low overhead over database/sql
- Broad dialect support including SQL Server and Oracle
- Small open issue count for its size
Limitations
- Column and table names in expressions are strings, so many errors are caught at run time
- Migrations are written by hand; no diffing from models
- Smaller community than GORM
- Maintained mainly by one company and one lead developer
Who it suits
Good for
- Go developers who like SQL but want scanning and relations handled
- Services that need OpenTelemetry tracing of queries
Look elsewhere if
- Teams that want compile-time query checking (sqlc or Ent)
- Projects that need generated migrations
Alternatives to Bun (Go ORM)
Questions
Is Bun related to the Bun JavaScript runtime?
No. This Bun is a Go ORM from Uptrace; the name is shared by coincidence.
Which databases does Bun support?
PostgreSQL, MySQL and MariaDB, Microsoft SQL Server, SQLite and Oracle.
Does Bun have migrations?
Yes, it runs Go and SQL migration files, but you write them yourself.
Sources read for this page