Bun is a Go ORM that keeps SQL visible while adding type-safe queries, scanning, and migrations across several SQL engines.
Overview
Bun is a Go package for working with relational databases using an SQL-first style. Instead of hiding SQL behind a heavy DSL, it lets you express selects, joins, and analytics-style queries in Go while staying close to the SQL you would write by hand.
The ORM targets PostgreSQL, MySQL and MariaDB, Microsoft SQL Server, SQLite, and Oracle, with dialect-specific drivers listed in the documentation. Query results can be scanned into structs, maps, scalars, or slices, and struct tags define table relationships including belongs-to style links.
Beyond basic CRUD, Bun supports schema migrations, fixtures, soft deletes, bulk operations, and query hooks such as debug logging. OpenTelemetry integration is documented for tracing database access in production setups.
Bun sits on top of Go’s database/sql with drivers for each supported backend, so you open a standard SQL connection and wrap it with Bun’s API. Complex queries can be composed step by step, including common table expressions chained with With, and the generated SQL is intended to match hand-written equivalents.
Key features
- SQL-first query building in Go
- PostgreSQL, MySQL, MSSQL, SQLite, Oracle
- Type-safe scanning into structs and slices
- Struct tags for table relationships
- Schema migrations and fixtures
- Soft delete support
- Query debug hooks
- OpenTelemetry tracing integration
Use cases
- Type-safe SQL in Go services
- Multi-database Go applications
- Complex analytical queries with CTEs
- ORM with visible generated SQL