explaingit

uptrace/bun

4,798GoAudience · developerComplexity · 3/5Setup · moderate

TLDR

A Go library that makes working with SQL databases easier by mapping Go structs to tables, supports PostgreSQL, MySQL, SQLite, SQL Server, and Oracle, with query building, migrations, and production monitoring built in.

Mindmap

mindmap
  root((Bun ORM))
    Databases
      PostgreSQL
      MySQL and MariaDB
      SQLite
      SQL Server
    Query building
      Insert and update
      Delete and select
      Chained methods
      Bulk operations
    Schema tools
      Struct annotations
      Table relationships
      Migrations system
    Monitoring
      Query logging
      OpenTelemetry tracing
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Replace raw SQL queries in a Go backend with typed struct-based queries that surface errors earlier.

USE CASE 2

Define table relationships in Go structs and let Bun handle joins and result scanning without manual SQL.

USE CASE 3

Track and apply database schema changes over time using Bun's versioned migrations system.

USE CASE 4

Add query logging and OpenTelemetry tracing to a Go application's database layer for production debugging.

Tech stack

GoPostgreSQLMySQLSQLiteSQL Server

Getting it running

Difficulty · moderate Time to first run · 30min

Requires installing the matching database driver package (e.g., pgdriver for PostgreSQL) alongside Bun itself.

In plain English

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.

Copy-paste prompts

Prompt 1
Using Bun for Go, define a User struct that maps to a users table with id, email, and created_at fields, then show me how to insert a new user and query all users by email domain.
Prompt 2
With Bun, model a one-to-many relationship between a User and their Posts in Go structs, then query a single user and eagerly load all their posts in one database call.
Prompt 3
Show me how to write a Bun migration in Go that adds a nullable profile_image_url column to an existing users table and rolls back safely if it fails.
Prompt 4
Set up Bun query logging in a Go app so every SQL statement prints to the console during local development, using an environment variable to disable it in production.
Open on GitHub → Explain another repo

← uptrace on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.