{"id":15686371,"url":"https://github.com/dhui/satomic","last_synced_at":"2025-05-07T18:41:04.234Z","repository":{"id":143442871,"uuid":"161880362","full_name":"dhui/satomic","owner":"dhui","description":"Simple nested SQL transactions/savepoints in Golang","archived":false,"fork":false,"pushed_at":"2025-04-18T20:43:02.000Z","size":241,"stargazers_count":9,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-19T07:46:10.722Z","etag":null,"topics":["database","golang","savepoints","sql","transaction-manager"],"latest_commit_sha":null,"homepage":null,"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/dhui.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,"zenodo":null}},"created_at":"2018-12-15T07:17:24.000Z","updated_at":"2025-04-18T20:43:05.000Z","dependencies_parsed_at":"2024-04-19T13:47:33.270Z","dependency_job_id":"4f61e1f3-5cb2-4230-895d-011afa946e85","html_url":"https://github.com/dhui/satomic","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dhui%2Fsatomic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dhui%2Fsatomic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dhui%2Fsatomic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dhui%2Fsatomic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dhui","download_url":"https://codeload.github.com/dhui/satomic/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252936103,"owners_count":21828075,"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","golang","savepoints","sql","transaction-manager"],"created_at":"2024-10-03T17:38:54.841Z","updated_at":"2025-05-07T18:41:04.224Z","avatar_url":"https://github.com/dhui.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# satomic\n\n![GitHub Workflow Status (branch)](https://img.shields.io/github/actions/workflow/status/dhui/satomic/go.yml?branch=master) [![Code Coverage](https://img.shields.io/codecov/c/github/dhui/satomic.svg)](https://codecov.io/gh/dhui/satomic) [![GoDoc](https://godoc.org/github.com/dhui/satomic?status.svg)](https://godoc.org/github.com/dhui/satomic) [![Go Report Card](https://goreportcard.com/badge/github.com/dhui/satomic)](https://goreportcard.com/report/github.com/dhui/satomic) [![GitHub Release](https://img.shields.io/github/release/dhui/satomic/all.svg)](https://github.com/dhui/satomic/releases) ![Supported Go versions](https://img.shields.io/badge/Go-1.23%2C%201.24-lightgrey.svg)\n\nsatomic is a Golang package that makes managing nested SQL transactions/savepoints easier\n\n## Overview\n\nCreate a `Querier` and use the `Atomic()` method. Any SQL statements inside the `Atomic()` method's callback function will be appropriately wrapped in a transaction or savepoint. Transaction and savepoint management will be handled for you automatically. Any error returned by the callback function (or unrecovered panic) will rollback the savepoint or transaction accordingly. A new `Querier` instance is also provided to the `Atomic()` method's callback function to allow nesting savepoints.\n\n## Status\n\nsatomic is **not stable yet**, so the **interfaces may change in a non-backwards compatible manner**.\nsatomic follows [Semantic Versioning 2.0.0](https://semver.org/). While the major version number is `0`, all backwards compatible changes will be denoted by a minor version number bump. All other changes will increase the patch version number.\n\n## Example usage\n\n```golang\npackage main\n\nimport (\n    \"context\"\n    \"database/sql\"\n    \"github.com/dhui/satomic\"\n    \"github.com/dhui/satomic/savepointers/postgres\"\n)\n\n// Error handling omitted for brevity. Actual code should handle errors\nfunc main() {\n    ctx := context.Background()\n    var db *sql.DB  // Use an actual db\n\n    // savepointer should match the db driver used\n    q, _ := satomic.NewQuerier(ctx, db, postgres.Savepointer{}, sql.TxOptions{})\n\n    q.Atomic(func(ctx context.Context, q satomic.Querier) error {\n        // In transaction\n        var dummy int\n        q.QueryRowContext(ctx, \"SELECT 1;\").Scan(\u0026dummy)\n\n        q.Atomic(func(ctx context.Context, q satomic.Querier) error {\n            // In first savepoint\n            return q.QueryRowContext(ctx, \"SELECT 2;\").Scan(\u0026dummy)\n        })\n\n        q.Atomic(func(ctx context.Context, q satomic.Querier) error {\n            // In second savepoint\n            q.QueryRowContext(ctx, \"SELECT 3;\").Scan(\u0026dummy)\n\n            q.Atomic(func(ctx context.Context, q satomic.Querier) error {\n                // In third savepoint\n                q.QueryRowContext(ctx, \"SELECT 4;\").Scan(\u0026dummy)\n                return nil\n            })\n\n            return nil\n        })\n\n        return nil\n    })\n}\n```\n\nA more complete example can be found in the [GoDoc](https://godoc.org/github.com/dhui/satomic)\n\nFor usage with [sqlx](https://github.com/jmoiron/sqlx), use [github.com/dhui/satomic/satomicx](https://godoc.org/github.com/dhui/satomic/satomicx)\n\n## What's with the name?\n\nGo **S**QL **atomic** =\u003e satomic\n\n---\n\nInspired by [sqlexp](https://github.com/golang-sql/sqlexp) and Django's [atomic](https://docs.djangoproject.com/en/2.1/topics/db/transactions/#django.db.transaction.atomic) decorator/context manager.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdhui%2Fsatomic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdhui%2Fsatomic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdhui%2Fsatomic/lists"}