{"id":13412276,"url":"https://github.com/alexeyco/pig","last_synced_at":"2026-02-11T17:15:46.534Z","repository":{"id":57577196,"uuid":"358308688","full_name":"alexeyco/pig","owner":"alexeyco","description":"Simple pgx wrapper to execute and scan query results","archived":false,"fork":false,"pushed_at":"2025-11-14T19:58:06.000Z","size":43,"stargazers_count":17,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-11-14T21:28:22.412Z","etag":null,"topics":["database","go","golang","pgx","postgres","postgresql","sql"],"latest_commit_sha":null,"homepage":"","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/alexeyco.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-04-15T15:33:23.000Z","updated_at":"2025-11-14T19:58:10.000Z","dependencies_parsed_at":"2022-09-11T23:41:07.169Z","dependency_job_id":null,"html_url":"https://github.com/alexeyco/pig","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/alexeyco/pig","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexeyco%2Fpig","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexeyco%2Fpig/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexeyco%2Fpig/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexeyco%2Fpig/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexeyco","download_url":"https://codeload.github.com/alexeyco/pig/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexeyco%2Fpig/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29339000,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-11T16:14:43.024Z","status":"ssl_error","status_checked_at":"2026-02-11T16:14:15.258Z","response_time":97,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["database","go","golang","pgx","postgres","postgresql","sql"],"created_at":"2024-07-30T20:01:22.889Z","updated_at":"2026-02-11T17:15:46.528Z","avatar_url":"https://github.com/alexeyco.png","language":"Go","funding_links":[],"categories":["Database Drivers","数据库驱动程序","Relational Databases","Data Integration Frameworks","Generators"],"sub_categories":["Relational Database Drivers","关系数据库驱动程序","Advanced Console UIs"],"readme":"# pig\n\n[![Build](https://github.com/alexeyco/pig/actions/workflows/test.yml/badge.svg)](https://github.com/alexeyco/pig/actions/workflows/test.yml)\n[![PkgGoDev](https://pkg.go.dev/badge/github.com/alexeyco/pig)](https://pkg.go.dev/github.com/alexeyco/pig)\n[![Go Report Card](https://goreportcard.com/badge/github.com/alexeyco/pig)](https://goreportcard.com/report/github.com/alexeyco/pig)\n[![Coverage Status](https://coveralls.io/repos/github/alexeyco/pig/badge.svg?branch=main)](https://coveralls.io/github/alexeyco/pig?branch=main)\n\nSimple [pgx](https://github.com/jackc/pgx) wrapper to execute and [scan](https://github.com/alexeyco/pig) query\nresults.\n\n## Features\n\n* All-in-one tool;\n* Simple transactions management:\n    * You can set `idle_in_transaction_session_timeout` local\n      option ([read more](https://www.postgresql.org/docs/9.6/runtime-config-client.html)),\n    * You can set `statement_timeout` local\n      option ([read more](https://www.postgresql.org/docs/9.6/runtime-config-client.html)).\n\n## Usage\n\n### Execute query\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"log\"\n\n\t\"github.com/alexeyco/pig\"\n\t\"github.com/jackc/pgx/v5\"\n)\n\nfunc main() {\n\tconn, err := pgx.Connect(context.Background(), \"\")\n\tif err != nil {\n\t\tlog.Fatalln(err)\n\t}\n\n\tp := pig.New(conn)\n\n\taffectedRows, err := p.Query().Exec(\"DELETE FROM things WHERE id = $1\", 123)\n\tif err != nil {\n\t\tlog.Fatalln(err)\n\t}\n\n\tlog.Println(\"affected\", affectedRows, \"rows\")\n}\n```\n\n### Get single entity\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"log\"\n\n\t\"github.com/alexeyco/pig\"\n\t\"github.com/jackc/pgx/v5\"\n)\n\nfunc main() {\n\tconn, err := pgx.Connect(context.Background(), \"\")\n\tif err != nil {\n\t\tlog.Fatalln(err)\n\t}\n\n\tp := pig.New(conn)\n\n\tvar cnt int64\n\terr = p.Query().Get(\u0026cnt, \"SELECT count(*) FROM things\")\n\tif err != nil {\n\t\tlog.Fatalln(err)\n\t}\n\n\tlog.Println(cnt, \"things found\")\n}\n```\n\n### Select multiple entities\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"log\"\n\n\t\"github.com/alexeyco/pig\"\n\t\"github.com/jackc/pgx/v5\"\n)\n\ntype Thing struct {\n\tID       int64  `db:\"id\"`\n\tName     string `db:\"name\"`\n\tQuantity int64  `db:\"quantity\"`\n}\n\nfunc main() {\n\tconn, err := pgx.Connect(context.Background(), \"\")\n\tif err != nil {\n\t\tlog.Fatalln(err)\n\t}\n\n\tp := pig.New(conn)\n\n\tvar things []Thing\n\terr = p.Query().Select(\u0026things, \"SELECT * FROM things\")\n\tif err != nil {\n\t\tlog.Fatalln(err)\n\t}\n\n\tlog.Println(things)\n}\n```\n\n### Make transactions\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"log\"\n\t\"time\"\n\n\t\"github.com/alexeyco/pig\"\n\t\"github.com/jackc/pgx/v5\"\n)\n\nfunc main() {\n\tconn, err := pgx.Connect(context.Background(), \"\")\n\tif err != nil {\n\t\tlog.Fatalln(err)\n\t}\n\n\tp := pig.New(conn)\n\n\tvar affectedRows int64\n\terr = p.Tx(pig.TransactionTimeout(time.Second)).\n\t\tExec(func(ex *pig.Ex) error {\n\t\t\taffectedRows, err = p.Query().Exec(\"DELETE FROM things WHERE id = $1\", 123)\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\n\t\t\treturn nil\n\t\t})\n\tif err != nil {\n\t\tlog.Fatalln(err)\n\t}\n\n\tlog.Println(\"affected\", affectedRows, \"rows\")\n}\n```\n\n## License\n\n```\nMIT License\n\nCopyright (c) 2021 Alexey Popov\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexeyco%2Fpig","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexeyco%2Fpig","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexeyco%2Fpig/lists"}