[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-10457":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":16,"stars7d":17,"stars30d":18,"stars90d":16,"forks30d":16,"starsTrendScore":19,"compositeScore":20,"rankGlobal":10,"rankLanguage":10,"license":21,"archived":22,"fork":22,"defaultBranch":23,"hasWiki":24,"hasPages":22,"topics":25,"createdAt":10,"pushedAt":10,"updatedAt":37,"readmeContent":38,"aiSummary":39,"trendingCount":16,"starSnapshotCount":16,"syncStatus":40,"lastSyncTime":41,"discoverSource":42},10457,"bun","uptrace\u002Fbun","uptrace","SQL-first Golang ORM","https:\u002F\u002Fbun.uptrace.dev",null,"Go",4851,279,28,25,0,9,63,3,70.14,"BSD 2-Clause \"Simplified\" License",false,"master",true,[26,27,28,29,30,31,32,33,34,35,36],"database","go","golang","mssql","mysql","oracle","orm","postgresql","sql","sqlite","sqlite3","2026-06-12 04:00:50","# Bun: SQL-first Golang ORM\n\n[![build workflow](https:\u002F\u002Fgithub.com\u002Fuptrace\u002Fbun\u002Factions\u002Fworkflows\u002Fbuild.yml\u002Fbadge.svg)](https:\u002F\u002Fgithub.com\u002Fuptrace\u002Fbun\u002Factions)\n[![PkgGoDev](https:\u002F\u002Fpkg.go.dev\u002Fbadge\u002Fgithub.com\u002Fuptrace\u002Fbun)](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fuptrace\u002Fbun)\n[![Documentation](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fbun-documentation-informational)](https:\u002F\u002Fbun.uptrace.dev\u002F)\n[![Chat](https:\u002F\u002Fdiscordapp.com\u002Fapi\u002Fguilds\u002F752070105847955518\u002Fwidget.png)](https:\u002F\u002Fdiscord.gg\u002FrWtp5Aj)\n[![Gurubase](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FGurubase-Ask%20Bun%20Guru-006BFF)](https:\u002F\u002Fgurubase.io\u002Fg\u002Fbun)\n\n**Lightweight, SQL-first Golang ORM for PostgreSQL, MySQL, MSSQL, SQLite, and Oracle**\n\nBun is a modern ORM that embraces SQL rather than hiding it. Write complex queries in Go with type\nsafety, powerful scanning capabilities, and database-agnostic code that works across multiple SQL\ndatabases.\n\n## ✨ Key Features\n\n- **SQL-first approach** - Write elegant, readable queries that feel like SQL\n- **Multi-database support** - PostgreSQL, MySQL\u002FMariaDB, MSSQL, SQLite, and Oracle\n- **Type-safe operations** - Leverage Go's static typing for compile-time safety\n- **Flexible scanning** - Query results into structs, maps, scalars, or slices\n- **Performance optimized** - Built on `database\u002Fsql` with minimal overhead\n- **Rich relationships** - Define complex table relationships with struct tags\n- **Production ready** - Migrations, fixtures, soft deletes, and OpenTelemetry support\n\n## 🚀 Quick Start\n\n```bash\ngo get github.com\u002Fuptrace\u002Fbun\n```\n\n### Basic Example\n\n```go\npackage main\n\nimport (\n    \"context\"\n    \"database\u002Fsql\"\n    \"fmt\"\n\n    \"github.com\u002Fuptrace\u002Fbun\"\n    \"github.com\u002Fuptrace\u002Fbun\u002Fdialect\u002Fsqlitedialect\"\n    \"github.com\u002Fuptrace\u002Fbun\u002Fdriver\u002Fsqliteshim\"\n)\n\nfunc main() {\n    ctx := context.Background()\n\n    \u002F\u002F Open database\n    sqldb, err := sql.Open(sqliteshim.ShimName, \"file::memory:\")\n    if err != nil {\n        panic(err)\n    }\n\n    \u002F\u002F Create Bun instance\n    db := bun.NewDB(sqldb, sqlitedialect.New())\n\n    \u002F\u002F Define model\n    type User struct {\n        ID   int64  `bun:\",pk,autoincrement\"`\n        Name string `bun:\",notnull\"`\n    }\n\n    \u002F\u002F Create table\n    db.NewCreateTable().Model((*User)(nil)).Exec(ctx)\n\n    \u002F\u002F Insert user\n    user := &User{Name: \"John Doe\"}\n    db.NewInsert().Model(user).Exec(ctx)\n\n    \u002F\u002F Query user\n    err = db.NewSelect().Model(user).Where(\"id = ?\", user.ID).Scan(ctx)\n    fmt.Printf(\"User: %+v\\n\", user)\n}\n```\n\n## 🎯 Why Choose Bun?\n\n### Elegant Complex Queries\n\nWrite sophisticated queries that remain readable and maintainable:\n\n```go\nregionalSales := db.NewSelect().\n    ColumnExpr(\"region\").\n    ColumnExpr(\"SUM(amount) AS total_sales\").\n    TableExpr(\"orders\").\n    GroupExpr(\"region\")\n\ntopRegions := db.NewSelect().\n    ColumnExpr(\"region\").\n    TableExpr(\"regional_sales\").\n    Where(\"total_sales > (SELECT SUM(total_sales) \u002F 10 FROM regional_sales)\")\n\nvar results []struct {\n    Region       string `bun:\"region\"`\n    Product      string `bun:\"product\"`\n    ProductUnits int    `bun:\"product_units\"`\n    ProductSales int    `bun:\"product_sales\"`\n}\n\nerr := db.NewSelect().\n    With(\"regional_sales\", regionalSales).\n    With(\"top_regions\", topRegions).\n    ColumnExpr(\"region, product\").\n    ColumnExpr(\"SUM(quantity) AS product_units\").\n    ColumnExpr(\"SUM(amount) AS product_sales\").\n    TableExpr(\"orders\").\n    Where(\"region IN (SELECT region FROM top_regions)\").\n    GroupExpr(\"region, product\").\n    Scan(ctx, &results)\n```\n\n### Flexible Result Scanning\n\nScan query results into various Go types:\n\n```go\n\u002F\u002F Into structs\nvar users []User\ndb.NewSelect().Model(&users).Scan(ctx)\n\n\u002F\u002F Into maps\nvar userMaps []map[string]interface{}\ndb.NewSelect().Table(\"users\").Scan(ctx, &userMaps)\n\n\u002F\u002F Into scalars\nvar count int\ndb.NewSelect().Table(\"users\").ColumnExpr(\"COUNT(*)\").Scan(ctx, &count)\n\n\u002F\u002F Into individual variables\nvar id int64\nvar name string\ndb.NewSelect().Table(\"users\").Column(\"id\", \"name\").Limit(1).Scan(ctx, &id, &name)\n```\n\n## 📊 Database Support\n\n| Database      | Driver                                     | Dialect               |\n| ------------- | ------------------------------------------ | --------------------- |\n| PostgreSQL    | `github.com\u002Fuptrace\u002Fbun\u002Fdriver\u002Fpgdriver`   | `pgdialect.New()`     |\n| MySQL\u002FMariaDB | `github.com\u002Fgo-sql-driver\u002Fmysql`           | `mysqldialect.New()`  |\n| SQLite        | `github.com\u002Fuptrace\u002Fbun\u002Fdriver\u002Fsqliteshim` | `sqlitedialect.New()` |\n| SQL Server    | `github.com\u002Fdenisenkom\u002Fgo-mssqldb`         | `mssqldialect.New()`  |\n| Oracle        | `github.com\u002Fsijms\u002Fgo-ora\u002Fv2`               | `oracledialect.New()` |\n\n## 🔧 Advanced Features\n\n### Table Relationships\n\nDefine complex relationships with struct tags:\n\n```go\ntype User struct {\n    ID      int64   `bun:\",pk,autoincrement\"`\n    Name    string  `bun:\",notnull\"`\n    Posts   []Post  `bun:\"rel:has-many,join:id=user_id\"`\n    Profile Profile `bun:\"rel:has-one,join:id=user_id\"`\n}\n\ntype Post struct {\n    ID     int64 `bun:\",pk,autoincrement\"`\n    Title  string\n    UserID int64\n    User   *User `bun:\"rel:belongs-to,join:user_id=id\"`\n}\n\n\u002F\u002F Load users with their posts\nvar users []User\nerr := db.NewSelect().\n    Model(&users).\n    Relation(\"Posts\").\n    Scan(ctx)\n```\n\n### Bulk Operations\n\nEfficient bulk operations for large datasets:\n\n```go\n\u002F\u002F Bulk insert\nusers := []User{{Name: \"John\"}, {Name: \"Jane\"}, {Name: \"Bob\"}}\n_, err := db.NewInsert().Model(&users).Exec(ctx)\n\n\u002F\u002F Bulk update with CTE\n_, err = db.NewUpdate().\n    Model(&users).\n    Set(\"updated_at = NOW()\").\n    Where(\"active = ?\", true).\n    Exec(ctx)\n\n\u002F\u002F Bulk delete\n_, err = db.NewDelete().\n    Model((*User)(nil)).\n    Where(\"created_at \u003C ?\", time.Now().AddDate(-1, 0, 0)).\n    Exec(ctx)\n```\n\n### Migrations\n\nVersion your database schema:\n\n```go\nimport \"github.com\u002Fuptrace\u002Fbun\u002Fmigrate\"\n\nmigrations := migrate.NewMigrations()\n\nmigrations.MustRegister(func(ctx context.Context, db *bun.DB) error {\n    _, err := db.NewCreateTable().Model((*User)(nil)).Exec(ctx)\n    return err\n}, func(ctx context.Context, db *bun.DB) error {\n    _, err := db.NewDropTable().Model((*User)(nil)).Exec(ctx)\n    return err\n})\n\nmigrator := migrate.NewMigrator(db, migrations)\nerr := migrator.Init(ctx)\nerr = migrator.Up(ctx)\n```\n\n## 📈 Monitoring & Observability\n\n### Debug Queries\n\nEnable query logging for development:\n\n```go\nimport \"github.com\u002Fuptrace\u002Fbun\u002Fextra\u002Fbundebug\"\n\ndb.AddQueryHook(bundebug.NewQueryHook(\n    bundebug.WithVerbose(true),\n))\n```\n\n### OpenTelemetry Integration\n\nProduction-ready observability with distributed tracing:\n\n```go\nimport \"github.com\u002Fuptrace\u002Fbun\u002Fextra\u002Fbunotel\"\n\ndb.AddQueryHook(bunotel.NewQueryHook(\n    bunotel.WithDBName(\"myapp\"),\n))\n```\n\n> **Monitoring made easy**: Bun is brought to you by ⭐\n> [**uptrace\u002Fuptrace**](https:\u002F\u002Fgithub.com\u002Fuptrace\u002Fuptrace). Uptrace is an open-source APM tool that\n> supports distributed tracing, metrics, and logs. You can use it to monitor applications and set up\n> automatic alerts to receive notifications via email, Slack, Telegram, and others.\n>\n> See [OpenTelemetry example](example\u002Fopentelemetry) which demonstrates how you can use Uptrace to\n> monitor Bun.\n\n## 📚 Documentation & Resources\n\n- **[Getting Started Guide](https:\u002F\u002Fbun.uptrace.dev\u002Fguide\u002Fgolang-orm.html)** - Comprehensive\n  tutorial\n- **[API Reference](https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fuptrace\u002Fbun)** - Complete package documentation\n- **[Examples](https:\u002F\u002Fgithub.com\u002Fuptrace\u002Fbun\u002Ftree\u002Fmaster\u002Fexample)** - Working code samples\n- **[Starter Kit](https:\u002F\u002Fgithub.com\u002Fgo-bun\u002Fbun-starter-kit)** - Production-ready template\n- **[Community Discussions](https:\u002F\u002Fgithub.com\u002Fuptrace\u002Fbun\u002Fdiscussions)** - Get help and share ideas\n\n## 🤝 Contributing\n\nWe welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details on how to\nget started.\n\n**Thanks to all our contributors:**\n\n\u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fuptrace\u002Fbun\u002Fgraphs\u002Fcontributors\">\n  \u003Cimg src=\"https:\u002F\u002Fcontributors-img.web.app\u002Fimage?repo=uptrace\u002Fbun\" alt=\"Contributors\" \u002F>\n\u003C\u002Fa>\n\n## 🔗 Related Projects\n\n- **[Golang HTTP router](https:\u002F\u002Fgithub.com\u002Fuptrace\u002Fbunrouter)** - Fast and flexible HTTP router\n- **[Golang msgpack](https:\u002F\u002Fgithub.com\u002Fvmihailenco\u002Fmsgpack)** - High-performance MessagePack\n  serialization\n\n---\n\n\u003Cdiv align=\"center\">\n  \u003Cstrong>Star ⭐ this repo if you find Bun useful!\u003C\u002Fstrong>\u003Cbr>\n  \u003Csub>Join our community on \u003Ca href=\"https:\u002F\u002Fdiscord.gg\u002FrWtp5Aj\">Discord\u003C\u002Fa> • Follow updates on \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fuptrace\u002Fbun\">GitHub\u003C\u002Fa>\u003C\u002Fsub>\n\u003C\u002Fdiv>\n","Bun 是一个轻量级的、以 SQL 优先的 Golang ORM，支持 PostgreSQL、MySQL、MSSQL、SQLite 和 Oracle 等多种数据库。其核心功能包括：SQL-first 的查询编写方式，多数据库兼容性，类型安全的操作，灵活的结果扫描以及针对性能进行了优化。Bun 通过 Go 的静态类型系统确保编译时的安全性，并允许开发者定义复杂的表关系。此外，它还提供了迁移、数据填充、软删除和 OpenTelemetry 支持等功能，使其非常适合需要高性能且跨多个 SQL 数据库的应用场景中使用。",2,"2026-06-11 03:28:38","top_topic"]