{"id":39580415,"url":"https://github.com/proost/dbresolver","last_synced_at":"2026-01-18T07:29:37.172Z","repository":{"id":65149613,"uuid":"579296878","full_name":"proost/dbresolver","owner":"proost","description":"The sqlx resolver and wrapper for database cluster","archived":false,"fork":false,"pushed_at":"2023-10-27T03:32:26.000Z","size":65,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-06-21T13:40:20.026Z","etag":null,"topics":["database","go","golang","mysql","postgresql","rdbms","sqlx"],"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/proost.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":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-12-17T08:04:23.000Z","updated_at":"2024-02-01T23:44:23.000Z","dependencies_parsed_at":"2023-01-02T15:25:02.250Z","dependency_job_id":"e637c94b-e796-42b8-afec-58ac794392ef","html_url":"https://github.com/proost/dbresolver","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/proost/dbresolver","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/proost%2Fdbresolver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/proost%2Fdbresolver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/proost%2Fdbresolver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/proost%2Fdbresolver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/proost","download_url":"https://codeload.github.com/proost/dbresolver/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/proost%2Fdbresolver/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28533165,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-18T00:39:45.795Z","status":"online","status_checked_at":"2026-01-18T02:00:07.578Z","response_time":98,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["database","go","golang","mysql","postgresql","rdbms","sqlx"],"created_at":"2026-01-18T07:29:37.091Z","updated_at":"2026-01-18T07:29:37.154Z","avatar_url":"https://github.com/proost.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dbresolver\n\ndbresolver is [sqlx](https://github.com/jmoiron/sqlx) resolver and wrapper for database cluster.\n\n[![CI](https://github.com/proost/dbresolver/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/proost/dbresolver/actions/workflows/ci.yml)\n[![Go Reference](https://pkg.go.dev/badge/github.com/proost/dbresolver.svg)](https://pkg.go.dev/github.com/proost/dbresolver)\n\n## Install\n\n```shell\ngo get github.com/proost/dbresolver\n```\n\n## Usage\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"log\"\n\t\n\t\"github.com/jmoiron/sqlx\"\n\t\"github.com/proost/dbresolver\"\n)\n\nfunc main() {\n    var (\n        primaryHost       = \"localhost\"\n        primaryPort       = 3306\n        primaryUser       = \"primary\"\n        primaryPassword   = \"\u003cpassword\u003e\"\n        secondaryHost     = \"localhost\"\n        secondaryPort     = 3307\n        secondaryUser     = \"secondary\"\n        secondaryPassword = \"\u003cpassword\u003e\"\n        dbname            = \"\u003cdbname\u003e\"\n    )\n    // DSNs\n    primaryDSN := fmt.Sprintf(\n        \"%s:%s@tcp(%s:%d)/%s\",\n        primaryUser,\n        primaryPassword,\n        primaryHost,\n        primaryPort,\n        dbname,\n    )\n    secondaryDSN := fmt.Sprintf(\n        \"%s:%s@tcp(%s:%d)/%s\",\n        secondaryUser,\n        secondaryPassword,\n        secondaryHost,\n        secondaryPort,\n        dbname,\n    )\n\n    // connect to primary\n    primaryDB := sqlx.MustOpen(\"mysql\", primaryDSN)\n    // connect to secondary\n    secondaryDB := sqlx.MustOpen(\"mysql\", secondaryDSN)\n\n    primaryDBsCfg := \u0026dbresolver.PrimaryDBsConfig{\n      DBs:             []*sqlx.DB{primaryDB},\n      ReadWritePolicy: dbresolver.ReadWrite,\n    }\n    resolver := dbresolver.MustNewDBResolver(primaryDBsCfg, dbresolver.WithSecondaryDBs(secondaryDB))\n    defer resolver.Close()\n\n    resolver.MustExecContext(context.Background(), \"INSERT INTO users (name) VALUES (?)\", \"foo\")\n    result, err := resolver.QueryxContext(context.Background(), `SELECT * FROM users WHERE name = \"foo\"`)\n    if err != nil {\n      log.Panic(err)\n    }\n\n    fmt.Println(result)\n}\n```\n\n## Important Notes\n\n- Primary Database will be used when you call these functions\n    - `Begin`\n    - `BeginTx`\n    - `BeginTxx`\n    - `Beginx`\n    - `Conn`\n    - `Connx`\n    - `Exec`\n    - `ExecContext`\n    - `MustBegin`\n    - `MustBeginTx`\n    - `MustExec`\n    - `MustExecContext`\n    - `NamedExec`\n    - `NamedExecContext`\n- Readable Database(Secondary Database or Primary Database depending on configuration) will be used when you call these functions\n    - `Get`\n    - `GetContext`\n    - `NamedQuery`\n    - `NamedQueryContext`\n    - `Query`\n    - `QueryContext`\n    - `QueryRow`\n    - `QueryRowContext`\n    - `QueryRowx`\n    - `QueryRowxContext`\n    - `Select`\n    - `SelectContext`\n\n## Contribution\n\nTo contribute to this project, you can open a PR or an issue.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fproost%2Fdbresolver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fproost%2Fdbresolver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fproost%2Fdbresolver/lists"}