{"id":23290823,"url":"https://github.com/imega/txwrapper","last_synced_at":"2026-05-10T06:45:45.556Z","repository":{"id":64303142,"uuid":"424520202","full_name":"iMega/txwrapper","owner":"iMega","description":"SQL transaction wrapper on golang","archived":false,"fork":false,"pushed_at":"2021-11-04T12:02:44.000Z","size":12,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-12T23:46:17.616Z","etag":null,"topics":["database","mysql","sql","sqlite3","transaction"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/iMega.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":"2021-11-04T08:22:31.000Z","updated_at":"2022-03-14T12:17:35.000Z","dependencies_parsed_at":"2023-01-15T10:01:06.730Z","dependency_job_id":null,"html_url":"https://github.com/iMega/txwrapper","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iMega%2Ftxwrapper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iMega%2Ftxwrapper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iMega%2Ftxwrapper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iMega%2Ftxwrapper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iMega","download_url":"https://codeload.github.com/iMega/txwrapper/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247526675,"owners_count":20953141,"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":["database","mysql","sql","sqlite3","transaction"],"created_at":"2024-12-20T05:12:56.692Z","updated_at":"2026-05-10T06:45:45.459Z","avatar_url":"https://github.com/iMega.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TxWrapper\n\nTxWrapper is a sql transaction wrapper. It helps to exclude writing code for\nrollback and commit commands.\n\n### Usage\n\n```go\nimport (\n    \"context\"\n    \"database/sql\"\n    \"fmt\"\n    \"io/ioutil\"\n    \"os\"\n\n    _ \"github.com/mattn/go-sqlite3\"\n    \"github.com/imega/txwrapper\"\n)\n\nfunc main() {\n    file, err := ioutil.TempFile(\"\", \"db\")\n    if err != nil {\n        log.Fatalf(\"failed to create tmp file, %w\", err)\n    }\n\n    filename := file.Name()\n    if err := file.Close(); err != nil {\n        log.Fatalf(\"failed to close tmp file, %w\", err)\n    }\n\n    db, err := sql.Open(\"sqlite3\", filename)\n    if err != nil {\n        log.Fatalf(\"failed to open db, %w\", err)\n    }\n\n    ctx := context.Background()\n    w := txwrapper.New(db)\n    err := w.Transaction(ctx, nil, func(ctx context.Context, tx *sql.Tx) error {\n        if err := createEmailTable(ctx, tx); err != nil {\n            return err\n        }\n\n        if err := addEmail(ctx, tx, \"info@example.com\"); err != nil {\n            return err\n        }\n\n        return nil\n    })\n    if err != nil {\n        log.Fatalf(\"failed to open db, %w\", err)\n    }\n\n    errDB := db.Close()\n    if err := os.Remove(filename); err != nil || errDB != nil {\n        log.Fatalf(\"failed to close db or remove tmp file, %w, %w\", errDB, err)\n    }\n}\n\nfunc createEmailTable(ctx context.Context, tx *sql.Tx) error {\n    q := `CREATE TABLE IF NOT EXISTS email (\n        email VARCHAR(64) NOT NULL\n    )`\n\n    if _, err := tx.ExecContext(ctx, q); err != nil {\n        return fmt.Errorf(\"failed to execute query, %w\", err)\n    }\n\n    return nil\n}\n\nfunc addEmail(ctx context.Context, tx *sql.Tx, email string) error {\n    q := `insert into email (email) values (?)`\n\n    if _, err := tx.ExecContext(ctx, q, email); err != nil {\n        return fmt.Errorf(\"failed to execute query, %w\", err)\n    }\n\n    return nil\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimega%2Ftxwrapper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimega%2Ftxwrapper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimega%2Ftxwrapper/lists"}