{"id":18737945,"url":"https://github.com/rocketlaunchr/mysql-go","last_synced_at":"2025-04-12T19:32:38.662Z","repository":{"id":57490121,"uuid":"155018289","full_name":"rocketlaunchr/mysql-go","owner":"rocketlaunchr","description":"Make mysql cancelation a breeze","archived":false,"fork":false,"pushed_at":"2019-10-17T02:37:04.000Z","size":40,"stargazers_count":40,"open_issues_count":2,"forks_count":6,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-05T06:55:33.880Z","etag":null,"topics":["cancellation","context","go","golang","mysql","transactions"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rocketlaunchr.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":"2018-10-27T23:20:32.000Z","updated_at":"2025-01-06T13:43:18.000Z","dependencies_parsed_at":"2022-09-02T10:51:11.129Z","dependency_job_id":null,"html_url":"https://github.com/rocketlaunchr/mysql-go","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rocketlaunchr%2Fmysql-go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rocketlaunchr%2Fmysql-go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rocketlaunchr%2Fmysql-go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rocketlaunchr%2Fmysql-go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rocketlaunchr","download_url":"https://codeload.github.com/rocketlaunchr/mysql-go/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248621357,"owners_count":21134819,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["cancellation","context","go","golang","mysql","transactions"],"created_at":"2024-11-07T15:27:31.102Z","updated_at":"2025-04-12T19:32:38.431Z","avatar_url":"https://github.com/rocketlaunchr.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Canceling MySQL in Go [![GoDoc](http://godoc.org/github.com/rocketlaunchr/mysql-go?status.svg)](http://godoc.org/github.com/rocketlaunchr/mysql-go) [![Go Report Card](https://goreportcard.com/badge/github.com/rocketlaunchr/mysql-go)](https://goreportcard.com/report/github.com/rocketlaunchr/mysql-go)\n\nThis package will properly implement context cancelation for MySQL. Without this package, context cancelation does not actually cancel a MySQL query.\n\nSee [Article](https://medium.com/@rocketlaunchr.cloud/canceling-mysql-in-go-827ed8f83b30) for details of the behind-the-scenes magic.\n\nThe API is designed to resemble the standard library. It is fully compatible with the [dbq](https://github.com/rocketlaunchr/dbq) package which allows for zero boilerplate database operations in Go.\n\n⭐ **the project to show your appreciation.**\n\n## Dependencies\n\n-   [Go MySQL Driver](https://github.com/go-sql-driver/mysql)\n\n## Installation\n\n```\ngo get -u github.com/rocketlaunchr/mysql-go\n```\n\n## QuickStart\n\n```go\n\nimport (\n   sql \"github.com/rocketlaunchr/mysql-go\"\n)\n\npool, _ := sql.Open(\"user:password@tcp(localhost:3306)/db\")\n\n```\n\n## Read Query\n\n```go\n\n// Obtain an exclusive connection\nconn, err := pool.Conn(ctx)\ndefer conn.Close() // Return the connection back to the pool\n\n// Perform your read operation.\nrows, err := conn.QueryContext(ctx, stmt)\nif err != nil {\n   return err\n}\n\n```\n\n## Write Query\n\n```go\n\n// Obtain an exclusive connection\nconn, err := pool.Conn(ctx)\ndefer conn.Close() // Return the connection back to the pool\n\n// Perform the write operation\ntx, err := conn.BeginTx(ctx, nil)\n\n_, err = tx.ExecContext(ctx, stmt)\nif err != nil {\n   return tx.Rollback()\n}\n\ntx.Commit()\n```\n\n## Cancel Query\n\nCancel the context. This will send a `KILL` signal to MySQL automatically.\n\nIt is highly recommended you set a KillerPool when you instantiate the `DB` object.\n\nThe KillerPool is used to call the `KILL` signal.\n\n## Reverse Proxy Support\n\nCheckout the `proxy-protection` branch if your database is behind a reverse proxy in order to better guarantee that you are killing the correct query.\n\n## Other useful packages\n\n-   [dataframe-go](https://github.com/rocketlaunchr/dataframe-go) - Statistics and data manipulation\n-   [dbq](https://github.com/rocketlaunchr/dbq) - Zero boilerplate database operations for Go\n-   [igo](https://github.com/rocketlaunchr/igo) - A Go transpiler with cool new syntax such as fordefer (defer for for-loops)\n-   [react](https://github.com/rocketlaunchr/react) - Build front end applications using Go\n-   [remember-go](https://github.com/rocketlaunchr/remember-go) - Cache slow database queries\n\n#\n\n### Legal Information\n\nThe license is a modified MIT license. Refer to `LICENSE` file for more details.\n\n**© 2018-19 PJ Engineering and Business Solutions Pty. Ltd.**\n\n### Final Notes\n\nFeel free to enhance features by issuing pull-requests.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frocketlaunchr%2Fmysql-go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frocketlaunchr%2Fmysql-go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frocketlaunchr%2Fmysql-go/lists"}