Bun Feature
Bun feature
The bun feature adds PostgreSQL persistence using Bun (by uptrace). Pass --use-bun during crank init or include bun in your --features list to use it instead of the default GORM.
What it provides
| File | Purpose |
|---|---|
internal/adapters/persistence/bun/db.go |
PostgreSQL connection via Bunβs pgdriver |
internal/adapters/persistence/bun/migrate.go |
Migration runner using golang-migrate |
internal/adapters/persistence/bun/user_repository.go |
Bun-backed UserRepository |
migrations/000001_init.up.sql |
Initial database schema |
migrations/000001_init.down.sql |
Initial schema rollback |
Tech stack
| Library | Purpose | Documentation |
|---|---|---|
| Bun | SQL-first Go ORM with query builder | bun.uptrace.dev |
| pgdriver | PostgreSQL driver used by Bun | bun.uptrace.dev |
| golang-migrate | Database migration tool | github.com/golang-migrate/migrate |
| PostgreSQL | Relational database | postgresql.org/docs |
Learning resources
- Bun documentation β bun.uptrace.dev (query builder, models, migrations, relations)
- Bun GitHub β github.com/uptrace/bun
- golang-migrate β github.com/golang-migrate/migrate
- PostgreSQL documentation β postgresql.org/docs
Notes
- Bun and GORM are mutually exclusive β a project cannot have both.
- Bunβs
crank make scaffoldgenerates Bun-backed repository implementations + create-table migrations. - If youβre already using the uptrace ecosystem (OpenTelemetry, go-redis), Bun fits naturally alongside those tools.