{"id":15239089,"url":"https://github.com/dreamph/dbre","last_synced_at":"2026-02-05T21:04:16.355Z","repository":{"id":223265939,"uuid":"759747253","full_name":"dreamph/dbre","owner":"dreamph","description":"Golang ORM Database Adapter (Support Bun/Gorm)","archived":false,"fork":false,"pushed_at":"2025-01-17T11:10:03.000Z","size":145,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-10T13:34:15.136Z","etag":null,"topics":["bun","database","database-adapter","database-orm","go-sql","golang","gorm","orm","query","repository","sql"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dreamph.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-02-19T09:03:26.000Z","updated_at":"2025-01-17T11:10:05.000Z","dependencies_parsed_at":"2024-02-29T06:28:31.000Z","dependency_job_id":"7645c47e-9a64-4234-a177-423924f8ecf4","html_url":"https://github.com/dreamph/dbre","commit_stats":null,"previous_names":["dreamph/dbre"],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/dreamph/dbre","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dreamph%2Fdbre","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dreamph%2Fdbre/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dreamph%2Fdbre/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dreamph%2Fdbre/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dreamph","download_url":"https://codeload.github.com/dreamph/dbre/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dreamph%2Fdbre/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29134249,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-05T20:50:26.975Z","status":"ssl_error","status_checked_at":"2026-02-05T20:49:26.082Z","response_time":65,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bun","database","database-adapter","database-orm","go-sql","golang","gorm","orm","query","repository","sql"],"created_at":"2024-09-29T10:05:15.957Z","updated_at":"2026-02-05T21:04:13.989Z","avatar_url":"https://github.com/dreamph.png","language":"Go","funding_links":["https://www.buymeacoffee.com/dreamph"],"categories":[],"sub_categories":[],"readme":"## Basic Usage\nFull Example [example](example)\n\nFull Example with Clean Architecture\n[example](https://github.com/dreamph/go-clean-architecture-template)\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"log\"\n\n\t\"github.com/dreamph/dbre\"\n\t\"github.com/dreamph/dbre/adapters/bun\"\n\tbunpg \"github.com/dreamph/dbre/adapters/bun/connectors/pg\"\n\t\"github.com/dreamph/dbre/adapters/gorm\"\n\tgormpg \"github.com/dreamph/dbre/adapters/gorm/connectors/pg\"\n\t\"github.com/dreamph/dbre/example/domain\"\n\t\"go.uber.org/zap\"\n)\n\nfunc getBunDB(logger *zap.Logger) (dbre.AppIDB, dbre.DBTx, error) {\n\tbunDB, err := bunpg.Connect(\u0026bunpg.Options{\n\t\tHost:           \"127.0.0.1\",\n\t\tPort:           \"5432\",\n\t\tDBName:         \"dream\",\n\t\tUser:           \"dream\",\n\t\tPassword:       \"password\",\n\t\tConnectTimeout: 2000,\n\t\tLogger:         logger,\n\t})\n\tif err != nil {\n\t\treturn nil, nil, err\n\t}\n\n\tappDB := bun.NewIDB(bunDB)\n\tdbTx := bun.NewDBTx(bunDB)\n\n\treturn appDB, dbTx, nil\n}\n\nfunc getGormDB(logger *zap.Logger) (dbre.AppIDB, dbre.DBTx, error) {\n\tbunDB, err := gormpg.Connect(\u0026gormpg.Options{\n\t\tHost:           \"127.0.0.1\",\n\t\tPort:           \"5432\",\n\t\tDBName:         \"dream\",\n\t\tUser:           \"dream\",\n\t\tPassword:       \"password\",\n\t\tConnectTimeout: 2000,\n\t\tLogger:         logger,\n\t})\n\tif err != nil {\n\t\treturn nil, nil, err\n\t}\n\n\tappDB := gorm.NewIDB(bunDB)\n\tdbTx := gorm.NewDBTx(bunDB)\n\n\treturn appDB, dbTx, nil\n}\n\nfunc main() {\n\tlogger, err := zap.NewDevelopment()\n\tif err != nil {\n\t\tlog.Fatalf(err.Error())\n\t}\n\tdefer logger.Sync()\n\n\tappDB, dbTx, err := getBunDB(logger)\n\t//appDB, dbTx, err := getGormDB(logger)\n\tif err != nil {\n\t\tlog.Fatalf(err.Error())\n\t}\n\tdefer func() {\n\t\terr := appDB.Close()\n\t\tif err != nil {\n\t\t\tlog.Fatalf(err.Error())\n\t\t}\n\t}()\n\n\tctx := context.Background()\n\n\t//Simple Usage\n\tcountryDbQuery := bun.New[domain.Country](appDB)\n\n\tdata := \u0026domain.Country{\n\t\tId:     \"1\",\n\t\tCode:   \"C1\",\n\t\tName:   \"Name\",\n\t\tStatus: 20,\n\t}\n\n\t// Create\n\t_, err = countryDbQuery.Create(ctx, data)\n\tif err != nil {\n\t\tlog.Fatalf(err.Error())\n\t}\n\n\t// Update\n\t_, err = countryDbQuery.Update(ctx, data)\n\tif err != nil {\n\t\tlog.Fatalf(err.Error())\n\t}\n\n\t// Find By PK\n\t_, err = countryDbQuery.FindByPK(ctx, \u0026domain.Country{\n\t\tId: \"1\",\n\t})\n\tif err != nil {\n\t\tlog.Fatalf(err.Error())\n\t}\n\n\t// Find One\n\t_, err = countryDbQuery.FindOne(ctx, \u0026domain.Country{\n\t\tCode: \"C1\",\n\t})\n\tif err != nil {\n\t\tlog.Fatalf(err.Error())\n\t}\n\n\t// Delete\n\terr = countryDbQuery.Delete(ctx, \u0026domain.Country{\n\t\tId: \"C1\",\n\t})\n\tif err != nil {\n\t\tlog.Fatalf(err.Error())\n\t}\n\n\t// Upsert\n\t_, err = countryDbQuery.Upsert(ctx, data, nil)\n\tif err != nil {\n\t\tlog.Fatalf(err.Error())\n\t}\n\n\t// Find One Where\n\twb := dbre.WhereBuilder{}\n\twb.Where(\"code = ?\", \"C1\")\n\tresult, err := countryDbQuery.FindOneWhere(ctx, wb.WhereCauses())\n\tif err != nil {\n\t\tlog.Fatalf(err.Error())\n\t}\n\tfmt.Println(result)\n\n\t// Query List Where\n\twb = dbre.WhereBuilder{}\n\twb.Where(\"status = ?\", 20)\n\n\tlist, total, err := countryDbQuery.QueryListWhere(ctx, wb.WhereCauses(), \u0026dbre.Limit{Offset: 0, PageSize: 10}, []string{\"name\"})\n\tif err != nil {\n\t\tlog.Fatalf(err.Error())\n\t}\n\tfmt.Println(list, total)\n\n\t// With Transaction\n\terr = dbTx.WithTx(ctx, func(ctx context.Context, appDB dbre.AppIDB) error {\n\t\tdata2 := \u0026domain.Country{\n\t\t\tId:     \"1\",\n\t\t\tCode:   \"C1\",\n\t\t\tName:   \"Name\",\n\t\t\tStatus: 20,\n\t\t}\n\t\t_, err = countryDbQuery.WithTx(appDB).Create(ctx, data2)\n\t\tif err != nil {\n\t\t\tlog.Fatalf(err.Error())\n\t\t}\n\n\t\tdata2.Name = \"Name2\"\n\t\tdata2.Status = 10\n\n\t\t_, err = countryDbQuery.WithTx(appDB).Update(ctx, data2)\n\t\tif err != nil {\n\t\t\tlog.Fatalf(err.Error())\n\t\t}\n\n\t\treturn nil\n\t})\n\tif err != nil {\n\t\tlog.Fatalf(err.Error())\n\t}\n}\n\n```\n\n\nBuy Me a Coffee\n=======\n[![\"Buy Me A Coffee\"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/dreamph)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdreamph%2Fdbre","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdreamph%2Fdbre","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdreamph%2Fdbre/lists"}