Replace raw SQL queries in a Go backend with typed struct-based queries that surface errors earlier.
Define table relationships in Go structs and let Bun handle joins and result scanning without manual SQL.
Track and apply database schema changes over time using Bun's versioned migrations system.
Add query logging and OpenTelemetry tracing to a Go application's database layer for production debugging.
Requires installing the matching database driver package (e.g., pgdriver for PostgreSQL) alongside Bun itself.
Bun is a library for Go developers that makes it easier to read from and write to SQL databases. It acts as an ORM, which means it maps Go data structures to database tables so you can work with data in code rather than writing raw database queries by hand. Unlike some ORMs that try to hide SQL entirely, Bun is built around SQL directly: the queries you write in Go closely mirror the SQL that gets sent to the database, so developers who know SQL will find the approach familiar. It works with several common database systems: PostgreSQL, MySQL and MariaDB, SQLite, Microsoft SQL Server, and Oracle. You pick the database you want, install the matching driver and dialect package, and Bun handles the translation between your Go structs and the database's own format. You can define how fields map to columns using short annotations on your struct definitions, and you can express relationships between tables (such as one user having many posts) directly in those structs. For everyday work, Bun provides methods to insert, update, delete, and query records. It can scan results into Go structs, maps, slices, or individual variables. For complex queries involving grouping, filtering, or multi-step logic, you can chain methods together to build the full query in Go code before executing it. Bulk inserts and updates for large datasets are also supported. The library includes tools for managing database schema changes over time through a migrations system, so you can track and apply changes to your database structure in a versioned way. For monitoring, there are hooks you can attach to log every query during development, and an integration with OpenTelemetry for production tracing. Bun is built by Uptrace, the same team behind an open-source application monitoring product. Documentation, examples, and a starter project template are available through links in the README.
← uptrace on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.