{"id":28441147,"url":"https://github.com/allisson/pgxutil","last_synced_at":"2025-09-15T03:22:18.982Z","repository":{"id":61623440,"uuid":"536077146","full_name":"allisson/pgxutil","owner":"allisson","description":"A collection of helpers to deal with pgx toolkit.","archived":false,"fork":false,"pushed_at":"2024-02-15T12:50:13.000Z","size":47,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-29T01:39:18.567Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/allisson.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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}},"created_at":"2022-09-13T10:40:53.000Z","updated_at":"2022-09-13T12:23:46.000Z","dependencies_parsed_at":"2024-02-15T13:49:48.964Z","dependency_job_id":"6a1dc6a7-ea8c-4c5f-8c65-6ee2dce275ff","html_url":"https://github.com/allisson/pgxutil","commit_stats":{"total_commits":13,"total_committers":2,"mean_commits":6.5,"dds":"0.46153846153846156","last_synced_commit":"4b30a544efb82f17facef8f549159673a2ed2965"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/allisson/pgxutil","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/allisson%2Fpgxutil","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/allisson%2Fpgxutil/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/allisson%2Fpgxutil/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/allisson%2Fpgxutil/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/allisson","download_url":"https://codeload.github.com/allisson/pgxutil/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/allisson%2Fpgxutil/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275198924,"owners_count":25422438,"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","status":"online","status_checked_at":"2025-09-15T02:00:09.272Z","response_time":75,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2025-06-06T04:09:01.604Z","updated_at":"2025-09-15T03:22:18.970Z","avatar_url":"https://github.com/allisson.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pgxutil\n[![Build Status](https://github.com/allisson/pgxutil/workflows/Release/badge.svg)](https://github.com/allisson/pgxutil/actions)\n[![Go Report Card](https://goreportcard.com/badge/github.com/allisson/pgxutil/v2)](https://goreportcard.com/report/github.com/allisson/pgxutil/v2)\n[![go.dev reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go\u0026logoColor=white\u0026style=flat-square)](https://pkg.go.dev/github.com/allisson/pgxutil/v2)\n\nA collection of helpers to deal with pgx toolkit.\n\nExample:\n\n```golang\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"log\"\n\n\t\"github.com/allisson/pgxutil/v2\"\n\t\"github.com/jackc/pgx/v5\"\n)\n\ntype Player struct {\n\tID   int    `db:\"id\"`\n\tName string `db:\"name\" fieldtag:\"insert,update\"`\n\tAge  int    `db:\"age\" fieldtag:\"insert,update\"`\n}\n\nfunc main() {\n\tctx := context.Background()\n\t// Run a database with docker: docker run --name test --restart unless-stopped -e POSTGRES_USER=user -e POSTGRES_PASSWORD=password -e POSTGRES_DB=pgxutil -p 5432:5432 -d postgres:14-alpine\n\t// Connect to database\n\tconn, err := pgx.Connect(ctx, \"postgres://user:password@localhost/pgxutil?sslmode=disable\")\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\tdefer conn.Close(ctx)\n\n\t// Create table\n\t_, err = conn.Exec(ctx, `\n\t\tCREATE TABLE IF NOT EXISTS players(\n\t\t\tid SERIAL PRIMARY KEY,\n\t\t\tname VARCHAR NOT NULL,\n\t\t\tage INTEGER NOT NULL\n\t\t)\n\t`)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\t// Insert players\n\tr9 := Player{\n\t\tName: \"Ronaldo Fenômeno\",\n\t\tAge:  44,\n\t}\n\tr10 := Player{\n\t\tName: \"Ronaldinho Gaúcho\",\n\t\tAge:  41,\n\t}\n\ttag := \"insert\" // will use fields with fieldtag:\"insert\"\n\tif err := pgxutil.Insert(ctx, conn, tag, \"players\", \u0026r9); err != nil {\n\t\tlog.Fatal(err)\n\t}\n\tif err := pgxutil.Insert(ctx, conn, tag, \"players\", \u0026r10); err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\t// Get player\n\tfindOptions := pgxutil.NewFindOptions().WithFilter(\"name\", r10.Name)\n\tif err := pgxutil.Get(ctx, conn, \"players\", findOptions, \u0026r10); err != nil {\n\t\tlog.Fatal(err)\n\t}\n\tfindOptions = pgxutil.NewFindOptions().WithFilter(\"name\", r9.Name)\n\tif err := pgxutil.Get(ctx, conn, \"players\", findOptions, \u0026r9); err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\t// Select players\n\tplayers := []*Player{}\n\tfindAllOptions := pgxutil.NewFindAllOptions().WithLimit(10).WithOffset(0).WithOrderBy(\"name asc\")\n\tif err := pgxutil.Select(ctx, conn, \"players\", findAllOptions, \u0026players); err != nil {\n\t\tlog.Fatal(err)\n\t}\n\tfor _, p := range players {\n\t\tfmt.Printf(\"%#v\\n\", p)\n\t}\n\n\t// Update player\n\ttag = \"update\" // will use fields with fieldtag:\"update\"\n\tr10.Name = \"Ronaldinho Bruxo\"\n\tif err := pgxutil.Update(ctx, conn, tag, \"players\", r10.ID, \u0026r10); err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\t// Delete player\n\tif err := pgxutil.Delete(ctx, conn, \"players\", r9.ID); err != nil {\n\t\tlog.Fatal(err)\n\t}\n}\n```\n\nOptions for FindOptions and FindAllOptions:\n\n```golang\npackage main\n\nimport (\n\t\"github.com/allisson/pgxutil/v2\"\n)\n\nfunc main() {\n\tfindOptions := pgxutil.NewFindOptions().\n\t\tWithFields([]string{\"id\", \"name\"}). // Return only id and name fields\n\t\tWithFilter(\"id\", 1).                // WHERE id = 1\n\t\tWithFilter(\"id\", nil).              // WHERE id IS NULL\n\t\tWithFilter(\"id.in\", \"1,2,3\").       // WHERE id IN (1, 2, 3)\n\t\tWithFilter(\"id.notin\", \"1,2,3\").    // WHERE id NOT IN ($1, $2, $3)\n\t\tWithFilter(\"id.not\", 1).            // WHERE id \u003c\u003e 1\n\t\tWithFilter(\"id.gt\", 1).             // WHERE id \u003e 1\n\t\tWithFilter(\"id.gte\", 1).            // WHERE id \u003e= 1\n\t\tWithFilter(\"id.lt\", 1).             // WHERE id \u003c 1\n\t\tWithFilter(\"id.lte\", 1).            // WHERE id \u003c= 1\n\t\tWithFilter(\"id.like\", 1).           // WHERE id LIKE 1\n\t\tWithFilter(\"id.null\", true).        // WHERE id.null IS NULL\n\t\tWithFilter(\"id.null\", false)        // WHERE id.null IS NOT NULL\n\n\tfindAllOptions := pgxutil.NewFindAllOptions().\n\t\tWithFields([]string{\"id\", \"name\"}). // Return only id and name fields\n\t\tWithFilter(\"id\", 1).                // WHERE id = 1\n\t\tWithFilter(\"id\", nil).              // WHERE id IS NULL\n\t\tWithFilter(\"id.in\", \"1,2,3\").       // WHERE id IN (1, 2, 3)\n\t\tWithFilter(\"id.notin\", \"1,2,3\").    // WHERE id NOT IN ($1, $2, $3)\n\t\tWithFilter(\"id.not\", 1).            // WHERE id \u003c\u003e 1\n\t\tWithFilter(\"id.gt\", 1).             // WHERE id \u003e 1\n\t\tWithFilter(\"id.gte\", 1).            // WHERE id \u003e= 1\n\t\tWithFilter(\"id.lt\", 1).             // WHERE id \u003c 1\n\t\tWithFilter(\"id.lte\", 1).            // WHERE id \u003c= 1\n\t\tWithFilter(\"id.like\", 1).           // WHERE id LIKE 1\n\t\tWithFilter(\"id.null\", true).        // WHERE id.null IS NULL\n\t\tWithFilter(\"id.null\", false).       // WHERE id.null IS NOT NULL\n\t\tWithLimit(10).                      // LIMIT 10\n\t\tWithOffset(0).                      // OFFSET 0\n\t\tWithOrderBy(\"name asc\").            // ORDER BY name asc\n\t\tWithForUpdate(\"SKIP LOCKED\")        // FOR UPDATE SKIP LOCKED\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fallisson%2Fpgxutil","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fallisson%2Fpgxutil","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fallisson%2Fpgxutil/lists"}