{"id":16002790,"url":"https://github.com/soreing/ssql","last_synced_at":"2025-04-05T01:26:10.064Z","repository":{"id":64298384,"uuid":"566677938","full_name":"Soreing/ssql","owner":"Soreing","description":"Golang SQL database wrapper with hooks","archived":false,"fork":false,"pushed_at":"2023-02-11T12:36:30.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-10T09:43:43.903Z","etag":null,"topics":["go","golang","hooks","sql"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Soreing.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2022-11-16T07:20:00.000Z","updated_at":"2023-02-11T14:51:48.000Z","dependencies_parsed_at":"2023-02-19T04:45:39.614Z","dependency_job_id":null,"html_url":"https://github.com/Soreing/ssql","commit_stats":null,"previous_names":["soreing/drape"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Soreing%2Fssql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Soreing%2Fssql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Soreing%2Fssql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Soreing%2Fssql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Soreing","download_url":"https://codeload.github.com/Soreing/ssql/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247274093,"owners_count":20912048,"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","hooks","sql"],"created_at":"2024-10-08T10:03:58.471Z","updated_at":"2025-04-05T01:26:10.047Z","avatar_url":"https://github.com/Soreing.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Simple SQL\nSimple SQL is a light wrapper around the native sql library, using easyscan to scan rows into objects and implementing hooks for additional logic around queries.\n\n## Usage\nGet a Database object through connection. The connection includes a ping to ensure that the opened connection is active. The examples use a PostgreSQL database.\n```golang\ndsn := \"host=127.0.0.1 port=5432 user=pg password=admin dbname=library\"\ndb, err := ssql.Connect(context.TODO(), \"postgres\", dsn)\nif err != nil {\n\tpanic(err)\n}\n```\n\nThere are only a handful of functions for interacting with the database to keep it simple. All functions require a context, and queries which return rows require a destination object that implement `easyscan.ScanOne` or `easyscan.ScanMany`. Queries require a query string and a list of optional parameters.\n```golang\nquery := `INSERT INTO books(id, title) VALUES($1, $2)`\nres, err := db.Exec(context.TODO(), query, 1, \"Beards and Beer\")\n```\n```golang\nbk := Book{}\nerr := db.Get(context.TODO(), \u0026bk, \"SELECT * FROM books WHERE id=$1\", 1)\n```\n```golang\nbkl := BookList{}\nerr := db.Select(context.TODO(), \u0026bkl, \"SELECT * FROM books\")\n```\nFor atomic operations with multiple queries, you can start a transaction. Transactions can be committed when finished or rolled back on error.\n```golang\ntx, err := db.Begin(context.TODO())\n```\n```golang\nquery := `UPDATE books SET title=$2 WHERE id=$1`\nres, err := db.Exec(context.TODO(), query, 1, \"The Ancient Earth\")\nif err != nil {\n    tx.Rollback(context.TODO())\n}\ntx.Commit(context.TODO())\n```\n\n## Hooks\nYou can attach hooks to databases which will be executed after the queries have been completed. Each hook function provides a QueryContext which contains details about the query. Transactions inherit hooks from the database context that started the transaction.\n```golang\ndb.UseHook(\n    func(ctx context.Context, qctx ssql.QueryContext, err error) {\n        if err != nil {\n            fmt.Println(qctx.Function, \" query failed\")\n        } else {\n            dur := time.Since(qctx.StartTime)\n            fmt.Println(qctx.Function, \" query succeeded in \", dur)\n        }\n    }\n)\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoreing%2Fssql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsoreing%2Fssql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoreing%2Fssql/lists"}