{"id":37202583,"url":"https://github.com/segmentio/nap","last_synced_at":"2026-01-14T23:21:57.028Z","repository":{"id":57498281,"uuid":"103422249","full_name":"segmentio/nap","owner":"segmentio","description":"A Go sql.DB wrapper for primary/replica topologies","archived":false,"fork":true,"pushed_at":"2024-07-09T15:49:13.000Z","size":18,"stargazers_count":4,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-25T05:35:22.833Z","etag":null,"topics":["paused"],"latest_commit_sha":null,"homepage":"http://godoc.org/github.com/tsenart/pan","language":"Go","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"tsenart/nap","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/segmentio.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":"2017-09-13T16:14:59.000Z","updated_at":"2024-07-09T15:49:17.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/segmentio/nap","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/segmentio/nap","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/segmentio%2Fnap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/segmentio%2Fnap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/segmentio%2Fnap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/segmentio%2Fnap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/segmentio","download_url":"https://codeload.github.com/segmentio/nap/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/segmentio%2Fnap/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28437981,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T22:37:52.437Z","status":"ssl_error","status_checked_at":"2026-01-14T22:37:31.496Z","response_time":107,"last_error":"SSL_read: 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":["paused"],"created_at":"2026-01-14T23:21:54.986Z","updated_at":"2026-01-14T23:21:56.958Z","avatar_url":"https://github.com/segmentio.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Nap\n\n\u003e **Note**\n\u003e Segment has paused maintenance on this project, but may return it to an active status in the future. Issues and pull requests from external contributors are not being considered, although internal contributions may appear from time to time. The project remains available under its open source license for anyone to use.\n\nNap is a library that abstracts access to primary-replica physical SQL servers topologies as a single logical database mimicking the standard `sql.DB` APIs.\n\n## Install\n```shell\n$ go get github.com/tsenart/nap\n```\n\n## Usage\n```go\npackage main\n\nimport (\n  \"log\"\n\n  \"github.com/tsenart/nap\"\n  _ \"github.com/go-sql-driver/mysql\" // Any sql.DB works\n)\n\nfunc main() {\n  // The first DSN is assumed to be the primary and all\n  // other to be replicas\n  dsns := \"tcp://user:password@primary/dbname;\"\n  dsns += \"tcp://user:password@replica01/dbname;\"\n  dsns += \"tcp://user:password@replica02/dbname\"\n\n  db, err := nap.Open(\"mysql\", dsns)\n  if err != nil {\n    log.Fatal(err)\n  }\n\n  if err := db.Ping(); err != nil {\n    log.Fatalf(\"Some physical database is unreachable: %s\", err)\n  }\n\n  // Read queries are directed to replicas with Query and QueryRow.\n  // Always use Query or QueryRow for SELECTS\n  // Load distribution is round-robin only for now.\n  var count int\n  err = db.QueryRow(\"SELECT COUNT(*) FROM sometable\").Scan(\u0026count)\n  if err != nil {\n    log.Fatal(err)\n  }\n\n  // Write queries are directed to the primary with Exec.\n  // Always use Exec for INSERTS, UPDATES\n  err = db.Exec(\"UPDATE sometable SET something = 1\")\n  if err != nil {\n    log.Fatal(err)\n  }\n\n  // Prepared statements are aggregates. If any of the underlying\n  // physical databases fails to prepare the statement, the call will\n  // return an error. On success, if Exec is called, then the\n  // primary is used, if Query or QueryRow are called, then a replica\n  // is used.\n  stmt, err := db.Prepare(\"SELECT * FROM sometable WHERE something = ?\")\n  if err != nil {\n    log.Fatal(err)\n  }\n\n  // Transactions always use the primary\n  tx, err := db.Begin()\n  if err != nil {\n    log.Fatal(err)\n  }\n  // Do something transactional ...\n  if err = tx.Commit(); err != nil {\n    log.Fatal(err)\n  }\n\n  // If needed, one can access the primary or a replica explicitly.\n  primary, replica := db.Primary(), db.Replica()\n}\n```\n\n## Todo\n* Support other replica load balancing algorithms.\n\n## License\nSee [LICENSE](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsegmentio%2Fnap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsegmentio%2Fnap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsegmentio%2Fnap/lists"}