{"id":37174294,"url":"https://github.com/benjaminbear/dbr","last_synced_at":"2026-01-14T20:22:09.058Z","repository":{"id":57658614,"uuid":"471646808","full_name":"benjaminbear/dbr","owner":"benjaminbear","description":"Additions to Go's database/sql for super fast performance and convenience.","archived":false,"fork":true,"pushed_at":"2022-03-19T13:34:14.000Z","size":326,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-06-20T15:54:10.946Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"gocraft/dbr","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/benjaminbear.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}},"created_at":"2022-03-19T09:19:31.000Z","updated_at":"2022-03-19T09:31:46.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/benjaminbear/dbr","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"purl":"pkg:github/benjaminbear/dbr","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benjaminbear%2Fdbr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benjaminbear%2Fdbr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benjaminbear%2Fdbr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benjaminbear%2Fdbr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/benjaminbear","download_url":"https://codeload.github.com/benjaminbear/dbr/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benjaminbear%2Fdbr/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28434427,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T18:57:19.464Z","status":"ssl_error","status_checked_at":"2026-01-14T18:52:48.501Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6: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":[],"created_at":"2026-01-14T20:22:08.492Z","updated_at":"2026-01-14T20:22:09.034Z","avatar_url":"https://github.com/benjaminbear.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# benjaminbear/dbr (database records)\n\n[![GoDoc](https://godoc.org/github.com/benjaminbear/dbr?status.png)](https://godoc.org/github.com/benjaminbear/dbr)\n[![FOSSA Status](https://app.fossa.com/api/projects/custom%2B4257%2Fgit%40github.com%3Abenjaminbear%2Fdbr.git.svg?type=shield)](https://app.fossa.com/projects/custom%2B4257%2Fgit%40github.com%benjaminbears%2Fdbr.git?ref=badge_shield)\n[![Go Report Card](https://goreportcard.com/badge/github.com/benjaminbear/dbr)](https://goreportcard.com/report/github.com/benjaminbear/dbr)\n[![CircleCI](https://circleci.com/gh/benjaminbear/dbr.svg?style=svg)](https://circleci.com/gh/benjaminbear/dbr)\n\nbenjaminbear/dbr provides additions to Go's database/sql for super fast performance and convenience.\n\n```\n$ go get -u github.com/benjaminbear/dbr/v2\n```\n\n```go\nimport \"github.com/benjaminbear/dbr/v2\"\n```\n\n## Driver support\n\n* MySQL\n* PostgreSQL\n* SQLite3\n* MsSQL\n\n## Examples\n\nSee [godoc](https://godoc.org/github.com/benjaminbear/dbr) for more examples.\n\n### Open connections\n\n```go\n// create a connection (e.g. \"postgres\", \"mysql\", or \"sqlite3\")\nconn, _ := Open(\"postgres\", \"...\", nil)\nconn.SetMaxOpenConns(10)\n\n// create a session for each business unit of execution (e.g. a web request or goworkers job)\nsess := conn.NewSession(nil)\n\n// create a tx from sessions\nsess.Begin()\n```\n\n### Create and use Tx\n\n```go\nsess := mysqlSession\ntx, err := sess.Begin()\nif err != nil {\n\treturn\n}\ndefer tx.RollbackUnlessCommitted()\n\n// do stuff...\n\ntx.Commit()\n```\n\n### SelectStmt loads data into structs\n\n```go\n// columns are mapped by tag then by field\ntype Suggestion struct {\n\tID\tint64\t\t// id, will be autoloaded by last insert id\n\tTitle\tNullString\t`db:\"subject\"`\t// subjects are called titles now\n\tUrl\tstring\t\t`db:\"-\"`\t// ignored\n\tsecret\tstring\t\t// ignored\n}\n\n// By default benjaminbear/dbr converts CamelCase property names to snake_case column_names.\n// You can override this with struct tags, just like with JSON tags.\n// This is especially helpful while migrating from legacy systems.\nvar suggestions []Suggestion\nsess := mysqlSession\nsess.Select(\"*\").From(\"suggestions\").Load(\u0026suggestions)\n```\n\n### SelectStmt with where-value interpolation\n\n```go\n// database/sql uses prepared statements, which means each argument\n// in an IN clause needs its own question mark.\n// benjaminbear/dbr, on the other hand, handles interpolation itself\n// so that you can easily use a single question mark paired with a\n// dynamically sized slice.\n\nsess := mysqlSession\nids := []int64{1, 2, 3, 4, 5}\nsess.Select(\"*\").From(\"suggestions\").Where(\"id IN ?\", ids)\n```\n\n### SelectStmt with joins\n\n```go\nsess := mysqlSession\nsess.Select(\"*\").From(\"suggestions\").\n\tJoin(\"subdomains\", \"suggestions.subdomain_id = subdomains.id\")\n\nsess.Select(\"*\").From(\"suggestions\").\n\tLeftJoin(\"subdomains\", \"suggestions.subdomain_id = subdomains.id\")\n\n// join multiple tables\nsess.Select(\"*\").From(\"suggestions\").\n\tJoin(\"subdomains\", \"suggestions.subdomain_id = subdomains.id\").\n\tJoin(\"accounts\", \"subdomains.accounts_id = accounts.id\")\n```\n\n### SelectStmt with raw SQL\n\n```go\nSelectBySql(\"SELECT `title`, `body` FROM `suggestions` ORDER BY `id` ASC LIMIT 10\")\n```\n\n### InsertStmt adds data from struct\n\n```go\ntype Suggestion struct {\n\tID\t\tint64\n\tTitle\t\tNullString\n\tCreatedAt\ttime.Time\n}\nsugg := \u0026Suggestion{\n\tTitle:\t\tNewNullString(\"Gopher\"),\n\tCreatedAt:\ttime.Now(),\n}\nsess := mysqlSession\nsess.InsertInto(\"suggestions\").\n\tColumns(\"title\").\n\tRecord(\u0026sugg).\n\tExec()\n\n// id is set automatically\nfmt.Println(sugg.ID)\n```\n\n### InsertStmt adds data from value\n\n```go\nsess := mysqlSession\nsess.InsertInto(\"suggestions\").\n\tPair(\"title\", \"Gopher\").\n\tPair(\"body\", \"I love go.\")\n```\n\n\n## Benchmark (2018-05-11)\n\n```\nBenchmarkLoadValues/sqlx_10-8         \t    5000\t    407318 ns/op\t    3913 B/op\t     164 allocs/op\nBenchmarkLoadValues/dbr_10-8          \t    5000\t    372940 ns/op\t    3874 B/op\t     123 allocs/op\nBenchmarkLoadValues/sqlx_100-8        \t    2000\t    584197 ns/op\t   30195 B/op\t    1428 allocs/op\nBenchmarkLoadValues/dbr_100-8         \t    3000\t    558852 ns/op\t   22965 B/op\t     937 allocs/op\nBenchmarkLoadValues/sqlx_1000-8       \t    1000\t   2319101 ns/op\t  289339 B/op\t   14031 allocs/op\nBenchmarkLoadValues/dbr_1000-8        \t    1000\t   2310441 ns/op\t  210092 B/op\t    9040 allocs/op\nBenchmarkLoadValues/sqlx_10000-8      \t     100\t  17004716 ns/op\t 3193997 B/op\t  140043 allocs/op\nBenchmarkLoadValues/dbr_10000-8       \t     100\t  16150062 ns/op\t 2394698 B/op\t   90051 allocs/op\nBenchmarkLoadValues/sqlx_100000-8     \t      10\t 170068209 ns/op\t31679944 B/op\t 1400053 allocs/op\nBenchmarkLoadValues/dbr_100000-8      \t      10\t 147202536 ns/op\t23680625 B/op\t  900061 allocs/op\n```\n\n## Thanks \u0026 Authors\nInspiration from these excellent libraries:\n* [sqlx](https://github.com/jmoiron/sqlx) - various useful tools and utils for interacting with database/sql.\n* [Squirrel](https://github.com/lann/squirrel) - simple fluent query builder.\n\nAuthors:\n* Jonathan Novak -- [https://github.com/cypriss](https://github.com/cypriss)\n* Tai-Lin Chu -- [https://github.com/taylorchu](https://github.com/taylorchu)\n* Sponsored by [UserVoice](https://eng.uservoice.com)\n\nContributors:\n* Paul Bergeron -- [https://github.com/dinedal](https://github.com/dinedal) - SQLite dialect\n\n## License\n[![FOSSA Status](https://app.fossa.com/api/projects/custom%2B4257%2Fgit%40github.com%3Abenjaminbear%2Fdbr.git.svg?type=large)](https://app.fossa.com/projects/custom%2B4257%2Fgit%40github.com%3Agocraft%2Fdbr.git?ref=badge_large)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenjaminbear%2Fdbr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbenjaminbear%2Fdbr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenjaminbear%2Fdbr/lists"}