{"id":16002870,"url":"https://github.com/soreing/sqlm","last_synced_at":"2025-04-05T01:26:19.904Z","repository":{"id":240599993,"uuid":"802912106","full_name":"Soreing/sqlm","owner":"Soreing","description":"Golang SQL package with middleware support","archived":false,"fork":false,"pushed_at":"2024-05-26T22:12:13.000Z","size":7,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-10T09:43:52.461Z","etag":null,"topics":["go","golang","middleware","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":"2024-05-19T15:42:07.000Z","updated_at":"2024-06-01T11:42:55.000Z","dependencies_parsed_at":"2024-10-30T14:40:50.401Z","dependency_job_id":null,"html_url":"https://github.com/Soreing/sqlm","commit_stats":null,"previous_names":["soreing/sqlm"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Soreing%2Fsqlm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Soreing%2Fsqlm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Soreing%2Fsqlm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Soreing%2Fsqlm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Soreing","download_url":"https://codeload.github.com/Soreing/sqlm/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247274121,"owners_count":20912054,"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","middleware","sql"],"created_at":"2024-10-08T10:04:41.765Z","updated_at":"2025-04-05T01:26:19.886Z","avatar_url":"https://github.com/Soreing.png","language":"Go","readme":"# SQLM\nSQLM is a light wrapper around the native sql package, providing middleware\nsupport to extend the features of specific functions.\n\n## Usage\nGet a Database object through connection. The examples use a PostgreSQL database.\n```golang\ndsn := \"host=127.0.0.1 port=5432 user=postgres password=postgres dbname=library sslmode=disable\"\ndb, err := sqlm.Open(\"postgres\", dsn)\nif err != nil {\n\tpanic(err)\n}\n```\n\nSQLM supports most of the native functions from database/sql, except QueryRow,\nbecause internally calls Query anyway, and *sql.Row is terrible.\n```golang\nctx := context.Background()\n\ntx, err := db.BeginTx(ctx, nil)\nif err != nil {\n    panic(err)\n}\n\nid := \"1d48e3ab-951d-404d-8e54-fa2d4f5f6bb6\"\nquery := \"INSERT INTO books(id, title) VALUES($1, $2) RETURNING id, title\"\nrows, err := tx.QueryContext(ctx, query, id, \"Beards and Beer\")\nif err != nil {\n    tx.Rollback()\n    panic(err)\n}\n\nvar rid, rtitle string\nfor rows.Next() {\n    if err = rows.Scan(\u0026rid, \u0026rtitle); err == nil {\n        fmt.Println(rid, rtitle)\n    }\n}\n\nif err = tx.Commit(); err != nil {\n    panic(err)\n}\n```\n\n## Middlewares\nSpecific sql functions support middleware handlers to be attached. These handlers\nare executed before the sql functions and allow for extending their features.\nMiddleware handlers are attached to the database *DB object and they get inherited\nwhen creating transactions, prepared statements and connections.\n\nEach handler has the original context as well as a query context in its parameter\nlist. The query context contains details and arguments for calling the sql function.\nThe query context DOES NOT implement context.Context, and is not used for calling \nany underlying sql functions.\n\nHandlers are attached on a selected list of sql functions.\n```golang\ntarget := []sqlm.Function{sqlm.FN_Query, sqlm.FN_Exec}\nhandler := func(ctx context.Context, qctx *sqlm.Context) {\n    fmt.Println(\"Running Query:\", qctx.Query, qctx.Args)\n    qctx.Next()\n    success := len(qctx.Errors()) == 0\n    fmt.Println(\"Success:\", success)\n}\n\ndb.Use(handler, target)\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoreing%2Fsqlm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsoreing%2Fsqlm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoreing%2Fsqlm/lists"}