{"id":37136931,"url":"https://github.com/tiendc/go-txhelper","last_synced_at":"2026-01-14T15:57:41.997Z","repository":{"id":204656373,"uuid":"712332863","full_name":"tiendc/go-txhelper","owner":"tiendc","description":"Golang SQL Tx execution library","archived":false,"fork":false,"pushed_at":"2024-09-11T11:41:05.000Z","size":8,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-09T21:41:13.391Z","etag":null,"topics":["go","golang","mysql","postgresql","sql","transaction"],"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/tiendc.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":"2023-10-31T09:04:21.000Z","updated_at":"2024-11-18T16:16:13.000Z","dependencies_parsed_at":null,"dependency_job_id":"1e18f21d-b4bd-48b8-995c-1eb31bcb19f2","html_url":"https://github.com/tiendc/go-txhelper","commit_stats":null,"previous_names":["tiendc/go-txhelper"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tiendc/go-txhelper","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tiendc%2Fgo-txhelper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tiendc%2Fgo-txhelper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tiendc%2Fgo-txhelper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tiendc%2Fgo-txhelper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tiendc","download_url":"https://codeload.github.com/tiendc/go-txhelper/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tiendc%2Fgo-txhelper/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28425587,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T15:24:48.085Z","status":"ssl_error","status_checked_at":"2026-01-14T15:23:41.940Z","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":["go","golang","mysql","postgresql","sql","transaction"],"created_at":"2026-01-14T15:57:41.275Z","updated_at":"2026-01-14T15:57:41.990Z","avatar_url":"https://github.com/tiendc.png","language":"Go","readme":"[![Go Version][gover-img]][gover] [![GoDoc][doc-img]][doc] [![Build Status][ci-img]][ci] [![Coverage Status][cov-img]][cov] [![GoReport][rpt-img]][rpt]\n\n# Golang SQL Tx helper library\n\nExecute SQL transaction with convenience.\n\n## Installation\n\n```shell\ngo get github.com/tiendc/go-txhelper\n```\n\n## Usage\n\n```go\nerr := txhelper.Execute(ctx, db, func (db *sql.Tx) error {\n    // Perform SQL statements with the inner `db`\n})\nif err != nil {\n    fmt.Println(err)\n}\n```\n\n### Set isolation level\n\n```go\nerr := txhelper.Execute(ctx, db, func (db *sql.Tx) error {\n    // Perform SQL statements with the inner `db`\n}, txhelper.IsolationLevel(sql.LevelReadCommitted))\n```\n\n### Retry on deadlock\n\nNormally a deadlock error can be retried instead of returning error.\n\n```go\n// For MySQL and when you use driver \"github.com/go-sql-driver/mysql\"\n\nimport \"github.com/go-sql-driver/mysql\"\nfunc IsMySQLDeadlock(err error) bool {\n    sqlErr := \u0026mysql.MySQLError{}\n    // Error 1213: Deadlock found when trying to get lock\n    // Error 1205: Lock wait timeout exceeded\n    return errors.As(err, \u0026sqlErr) \u0026\u0026 (sqlErr.Number == 1213 || sqlErr.Number == 1205)\n}\n\nerr := txhelper.Execute(ctx, db, func (db *sql.Tx) error {\n    // Perform SQL statements with the inner `db`\n}, txhelper.CheckRetryable(IsMySQLDeadlock),\n    txhelper.MaxRetryTimes(3),            // optional, default is 3\n    txhelper.RetryDelay(3 * time.Second), // optional, default is 0 - no delay\n)\n```\n\n```go\n// For Postgres and when you use driver \"github.com/lib/pq\"\n\nimport \"github.com/lib/pq\"\nfunc IsPostgresDeadlock(err error) bool {\n    sqlErr := \u0026pq.Error{}\n    return errors.As(err, \u0026sqlErr) \u0026\u0026 (sqlErr.Code == \"40P01\")\n}\n\nerr := txhelper.Execute(ctx, db, func (db *sql.Tx) error {\n    // Perform SQL statements with the inner `db`\n}, txhelper.CheckRetryable(IsPostgresDeadlock))\n```\n\n## Contributing\n\n- You are welcome to make pull requests for new functions and bug fixes.\n\n## License\n\n- [MIT License](LICENSE)\n\n[doc-img]: https://pkg.go.dev/badge/github.com/tiendc/go-txhelper\n[doc]: https://pkg.go.dev/github.com/tiendc/go-txhelper\n[gover-img]: https://img.shields.io/badge/Go-%3E%3D%201.18-blue\n[gover]: https://img.shields.io/badge/Go-%3E%3D%201.18-blue\n[ci-img]: https://github.com/tiendc/go-txhelper/actions/workflows/go.yml/badge.svg\n[ci]: https://github.com/tiendc/go-txhelper/actions/workflows/go.yml\n[cov-img]: https://codecov.io/gh/tiendc/go-txhelper/branch/main/graph/badge.svg\n[cov]: https://codecov.io/gh/tiendc/go-txhelper\n[rpt-img]: https://goreportcard.com/badge/github.com/tiendc/go-txhelper\n[rpt]: https://goreportcard.com/report/github.com/tiendc/go-txhelper\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftiendc%2Fgo-txhelper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftiendc%2Fgo-txhelper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftiendc%2Fgo-txhelper/lists"}