{"id":13367092,"url":"https://github.com/DATA-DOG/Go-txdb","last_synced_at":"2025-03-12T18:31:51.885Z","repository":{"id":34757911,"uuid":"38739169","full_name":"DATA-DOG/go-txdb","owner":"DATA-DOG","description":"Immutable transaction isolated sql driver for golang","archived":false,"fork":false,"pushed_at":"2025-03-06T13:53:03.000Z","size":219,"stargazers_count":701,"open_issues_count":4,"forks_count":49,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-03-10T21:46:24.947Z","etag":null,"topics":["go","golang","integration-testing","sql","sql-driver","tdd","testing"],"latest_commit_sha":null,"homepage":"","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/DATA-DOG.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":["l3pp4rd","flimzy","Yiling-J"]}},"created_at":"2015-07-08T07:34:53.000Z","updated_at":"2025-03-03T10:03:06.000Z","dependencies_parsed_at":"2022-08-17T20:00:20.954Z","dependency_job_id":"2ed15144-d8e8-4d3b-820f-593b4f5bc9df","html_url":"https://github.com/DATA-DOG/go-txdb","commit_stats":{"total_commits":68,"total_committers":18,"mean_commits":"3.7777777777777777","dds":0.6617647058823529,"last_synced_commit":"367bc925960552dbae889f70570fbefb28775451"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DATA-DOG%2Fgo-txdb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DATA-DOG%2Fgo-txdb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DATA-DOG%2Fgo-txdb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DATA-DOG%2Fgo-txdb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DATA-DOG","download_url":"https://codeload.github.com/DATA-DOG/go-txdb/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243271416,"owners_count":20264453,"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":["go","golang","integration-testing","sql","sql-driver","tdd","testing"],"created_at":"2024-07-30T00:01:38.448Z","updated_at":"2025-03-12T18:31:51.621Z","avatar_url":"https://github.com/DATA-DOG.png","language":"Go","readme":"[![Build Status](https://travis-ci.org/DATA-DOG/go-txdb.svg?branch=master)](https://travis-ci.org/DATA-DOG/go-txdb)\n[![GoDoc](https://godoc.org/github.com/DATA-DOG/go-txdb?status.svg)](https://godoc.org/github.com/DATA-DOG/go-txdb)\n\n# Single transaction based sql.Driver for GO\n\nPackage **txdb** is a single transaction based database sql driver. When the connection\nis opened, it starts a transaction and all operations performed on this **sql.DB**\nwill be within that transaction. If concurrent actions are performed, the lock is\nacquired and connection is always released the statements and rows are not holding the\nconnection.\n\nWhy is it useful. A very basic use case would be if you want to make functional tests\nyou can prepare a test database and within each test you do not have to reload a database.\nAll tests are isolated within transaction and though, performs fast. And you do not have\nto interface your **sql.DB** reference in your code, **txdb** is like a standard **sql.Driver**.\n\nThis driver supports any **sql.Driver** connection to be opened. You can register txdb\nfor different sql drivers and have it under different driver names. Under the hood\nwhenever a txdb driver is opened, it attempts to open a real connection and starts\ntransaction. When close is called, it rollbacks transaction leaving your prepared\ntest database in the same state as before.\n\nGiven, you have a mysql database called **txdb_test** and a table **users** with a **username**\ncolumn.\n\n``` go\npackage main\n\nimport (\n    \"database/sql\"\n    \"log\"\n\n    \"github.com/DATA-DOG/go-txdb\"\n    _ \"github.com/go-sql-driver/mysql\"\n)\n\nfunc init() {\n    // we register an sql driver named \"txdb\"\n    txdb.Register(\"txdb\", \"mysql\", \"root@/txdb_test\")\n}\n\nfunc main() {\n    // dsn serves as an unique identifier for connection pool\n    db, err := sql.Open(\"txdb\", \"identifier\")\n    if err != nil {\n        log.Fatal(err)\n    }\n    defer db.Close()\n\n    if _, err := db.Exec(`INSERT INTO users(username) VALUES(\"gopher\")`); err != nil {\n        log.Fatal(err)\n    }\n}\n```\n\nYou can also use [`sql.OpenDB`](https://golang.org/pkg/database/sql/#OpenDB) (added in Go 1.10) rather than registering a txdb driver instance, if you prefer:\n\n``` go\npackage main\n\nimport (\n    \"database/sql\"\n    \"log\"\n\n    \"github.com/DATA-DOG/go-txdb\"\n    _ \"github.com/go-sql-driver/mysql\"\n)\n\nfunc main() {\n    db := sql.OpenDB(txdb.New(\"mysql\", \"root@/txdb_test\"))\n    defer db.Close()\n\n    if _, err := db.Exec(`INSERT INTO users(username) VALUES(\"gopher\")`); err != nil {\n        log.Fatal(err)\n    }\n}\n```\n\nEvery time you will run this application, it will remain in the same state as before.\n\n### Testing\n\nUsage is mainly intended for testing purposes. Tests require database access, support using `postgres` and `mysql` databases. The easiest way to do this is by using [testcontainers](https://golang.testcontainers.org/), which is enabled by setting the respective database DSN values to `AUTO`. Example:\n\n```bash\nMYSQL_DSN=AUTO PSQL_DSN=AUTO go test ./...\n```\n\nIf you wish to use a running local database instance, you can also provide the DSN directly, and it will be used:\n\n```bash\nMYSQL_DSN=root:pass@/ PSQL_DSN=postgres://postgres:pass@localhost/ go test ./...\n```\n\nTo run tests only against MySQL or PostgreSQL, you may provide only the respective DSN values; any unset DSN is skipped for tests.\n\n### Documentation\n\nSee [godoc][godoc] for general API details.\nSee **.travis.yml** for supported **go** versions.\n\n### Contributions\n\nFeel free to open a pull request. Note, if you wish to contribute an extension to public (exported methods or types) -\nplease open an issue before to discuss whether these changes can be accepted. All backward incompatible changes are\nand will be treated cautiously.\n\nThe public API is locked since it is an **sql.Driver** and will not change.\n\n### License\n\n**txdb** is licensed under the [three clause BSD license][license]\n\n[godoc]: http://godoc.org/github.com/DATA-DOG/go-txdb \"Documentation on\ngodoc\"\n\n[golang]: https://golang.org/  \"GO programming language\"\n\n[license]:http://en.wikipedia.org/wiki/BSD_licenses \"The three clause BSD license\"\n","funding_links":["https://github.com/sponsors/l3pp4rd","https://github.com/sponsors/flimzy","https://github.com/sponsors/Yiling-J"],"categories":["测试","測試"],"sub_categories":["高级控制台界面","高級控制台界面"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDATA-DOG%2FGo-txdb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FDATA-DOG%2FGo-txdb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDATA-DOG%2FGo-txdb/lists"}