DEV.co
Open-Source Databases · uptrace

bun

Bun is a lightweight, SQL-first ORM for Go that supports PostgreSQL, MySQL, MSSQL, SQLite, and Oracle. It prioritizes readable SQL queries with type safety over abstraction, and includes features like migrations, relationships, and OpenTelemetry integration.

Source: GitHub — github.com/uptrace/bun
4.9k
GitHub stars
281
Forks
Go
Primary language
BSD-2-Clause
License (OSI-approved)

Key facts

Objective fields from the source. Values we can't verify are shown as “Unknown” rather than guessed.

FieldValue
Repositoryuptrace/bun
Owneruptrace
Primary languageGo
LicenseBSD-2-Clause — OSI-approved
Stars4.9k
Forks281
Open issues31
Latest releasev1.2.18 (2026-02-28)
Last updated2026-06-17
Sourcehttps://github.com/uptrace/bun

What bun is

Bun provides a query builder API layered on Go's `database/sql`, supporting complex CTEs, bulk operations, flexible result scanning into structs/maps/scalars, and struct-tag-based relationship definitions. It emphasizes compile-time type safety and minimal abstraction overhead.

Quickstart

Get the bun source

Clone the repository and explore it locally.

terminalbash
git clone https://github.com/uptrace/bun.gitcd bun# follow the project's README for install & configuration

Need it deployed, integrated, or customized instead? DEV.co ships production installs.

Best use cases

Complex analytical or reporting queries

Teams needing sophisticated multi-step queries (CTEs, window functions, subqueries) that remain readable and maintainable. Bun's SQL-first design and flexible scanning into custom structs align well with ad-hoc reporting workflows.

Multi-database Go backends

Applications requiring portability across PostgreSQL, MySQL, SQLite, and other SQL databases without rewriting query logic. Bun's dialect-based approach and consistent API simplify cross-database support.

High-performance CRUD with relationships

Services handling bulk inserts, updates, deletes, and eager-loading of related entities. Bun's built on `database/sql` (no connection pooling overhead) and supports efficient bulk operations and relation preloading.

Implementation considerations

  • Requires Go 1.16+ and explicit driver installation per database (e.g., `pgdriver`, `sqliteshim`, or third-party drivers like `go-sql-driver/mysql`).
  • Struct tag syntax (`bun:"..."`) defines columns, relationships, and constraints; errors in tags may only surface at runtime.
  • No automatic enum or advanced type coercion; custom scanning and marshaling may be needed for complex column types.
  • Migrations are code-based (up/down functions); teams must maintain migration files separately from models or use ORM-specific migration registry.
  • Connection pooling and lifecycle management remain the responsibility of the caller (use standard `sql.DB` configuration).

When to avoid it — and what to weigh

  • NoSQL or document-oriented data — Bun is SQL-only. Projects requiring MongoDB, DynamoDB, or similar non-relational stores need a different ORM or driver.
  • Schema-first, auto-migration-heavy workflows — Bun favors explicit, code-driven schema management. Teams heavily reliant on ORM auto-migration from Go struct tags alone may find Bun's migration approach more manual.
  • Tightly coupled frameworks (e.g., gRPC-first services with minimal DB logic) — Bun is a database-specific library. Applications better served by a full framework (e.g., Gin, Echo with built-in ORM abstraction) may find standalone use less integrated.
  • Strict ORM paradigm (model-first design) — If your team requires heavy model-centric abstractions (Rails-like pattern), Bun's SQL-first philosophy may feel lower-level and less 'magical'.

License & commercial use

BSD-2-Clause (Simplified BSD License): permissive, allows commercial use, modification, and distribution with minimal restrictions. Requires preservation of copyright notice and license text.

BSD-2-Clause is a permissive OSI-approved license. Commercial use is explicitly permitted. Ensure copyright and license notices are preserved in distributions. No warranty or liability protection is provided by the license; review Bun's LICENSES file for any additional disclaimers.

DEV.co evaluation signals

Editorial assessment — not user reviews. Directional, with an explicit confidence level.

SignalAssessment
MaintenanceActive
DocumentationStrong
License clarityClear
Deployment complexityLow
DEV.co fitStrong
Assessment confidenceHigh
Security considerations

Bun uses parameterized queries (via `database/sql`) to prevent SQL injection when used correctly; always bind user input via query parameters, not string concatenation. No security audit details provided in the source data. Applications should conduct standard Go dependency security reviews (e.g., `go list -json -m all | nancy sleuth`) and keep Bun and drivers updated. Connection pooling and authentication are handled by underlying drivers; review driver security posture separately.

Alternatives to consider

sqlc

Type-safe SQL code generation; shifts complexity to code generation rather than runtime queries. Better for teams preferring explicit SQL files over query builders. Does not provide ORM features (relationships, scanning helpers).

GORM

Heavier, more feature-rich ORM with stronger model-centric design, auto-migrations, and more conventions. Better if you want 'Rails-like' feel; less performant on complex queries due to abstraction overhead.

ent

Code-generated entity framework with schema definition in Go code. Stronger static guarantees and graph traversal; more opinionated and requires code generation step. Fewer databases supported than Bun.

Software development agency

Build on bun with DEV.co software developers

Contact a Devco engineer to assess fit, design a POC, or integrate Bun into your existing backend architecture.

Talk to DEV.co

Related open-source tools

Surfaced by semantic similarity across the DEV.co open-source index.

Related on DEV.co

Explore the category and the services that help you build with it.

bun FAQ

Does Bun require a separate daemon or service?
No. Bun is a Go library that links into your binary. You only need a reachable SQL database (PostgreSQL, MySQL, SQLite, etc.) and the appropriate driver installed.
Can I use Bun with an existing schema?
Yes. Define Go structs with `bun` tags matching your existing columns and relationships. Bun supports both schema-first (define struct tags to match DB) and code-first (create tables from structs) workflows.
How does Bun handle migrations?
Bun provides a migration package (`bun/migrate`) for versioning schema changes. Migrations are Go functions (up/down) registered in code. No auto-migration from struct changes; migrations are explicit and manual.
Is Bun suitable for microservices?
Yes. Bun is lightweight, integrates with OpenTelemetry for observability, and supports efficient bulk operations. Typical use is one Bun instance per service with its own database connection pool.

Custom software development services

DEV.co is a software development agency delivering custom software development services to companies building on open source. Our software developers and web developers design, integrate, and ship production systems — spanning web development, APIs, AI, data, and cloud. If bun is part of your open-source databases roadmap, our team can implement, customize, migrate, and maintain it.

Ready to evaluate Bun for your Go project?

Contact a Devco engineer to assess fit, design a POC, or integrate Bun into your existing backend architecture.