{"id":50812743,"url":"https://github.com/pgx-contrib/pgxquery","last_synced_at":"2026-06-13T06:33:43.733Z","repository":{"id":353884736,"uuid":"1220043760","full_name":"pgx-contrib/pgxquery","owner":"pgx-contrib","description":"pgx QueryRewriter that injects dynamic WHERE and ORDER BY clauses via SQL sentinel comments — safe, parameterised, zero-magic","archived":false,"fork":false,"pushed_at":"2026-06-05T21:24:09.000Z","size":71,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-05T23:10:13.142Z","etag":null,"topics":["dynamic-filtering","dynamic-ordering","go","golang","order-by","pgx","postgres","postgresql","query-rewriter","sqlc","where-clause"],"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/pgx-contrib.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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-04-24T13:39:25.000Z","updated_at":"2026-06-05T21:24:05.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/pgx-contrib/pgxquery","commit_stats":null,"previous_names":["pgx-contrib/pgxquery"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/pgx-contrib/pgxquery","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgx-contrib%2Fpgxquery","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgx-contrib%2Fpgxquery/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgx-contrib%2Fpgxquery/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgx-contrib%2Fpgxquery/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pgx-contrib","download_url":"https://codeload.github.com/pgx-contrib/pgxquery/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgx-contrib%2Fpgxquery/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34275068,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-13T02:00:06.617Z","response_time":62,"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":["dynamic-filtering","dynamic-ordering","go","golang","order-by","pgx","postgres","postgresql","query-rewriter","sqlc","where-clause"],"created_at":"2026-06-13T06:33:42.967Z","updated_at":"2026-06-13T06:33:43.723Z","avatar_url":"https://github.com/pgx-contrib.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pgxquery\n\n[![CI](https://github.com/pgx-contrib/pgxquery/actions/workflows/ci.yml/badge.svg)](https://github.com/pgx-contrib/pgxquery/actions/workflows/ci.yml)\n[![Release](https://img.shields.io/github/v/release/pgx-contrib/pgxquery?include_prereleases)](https://github.com/pgx-contrib/pgxquery/releases)\n[![Go Reference](https://pkg.go.dev/badge/github.com/pgx-contrib/pgxquery.svg)](https://pkg.go.dev/github.com/pgx-contrib/pgxquery)\n[![License](https://img.shields.io/github/license/pgx-contrib/pgxquery)](LICENSE)\n[![Go](https://img.shields.io/badge/Go-1.25-00ADD8?logo=go\u0026logoColor=white)](https://go.dev)\n[![pgx](https://img.shields.io/badge/pgx-v5-blue)](https://github.com/jackc/pgx)\n\nA [pgx](https://github.com/jackc/pgx) `QueryRewriter` adapter that substitutes\nsentinel comments in your SQL with dynamic `WHERE` and `ORDER BY` fragments at\nquery time. Write your SQL with `/* AND query.where */` and `/* , query.order_by */`\nmarkers, set the `Where` / `OrderBy` strings on a `QueryRewriter`, and let it\nsplice them in — preserving your chosen connective or separator verbatim.\n\n## Installation\n\n```bash\ngo get github.com/pgx-contrib/pgxquery\n```\n\n## Usage\n\nPlace sentinel comments in your SQL at the positions where dynamic fragments\nshould appear. Each sentinel has the form `/* \u003cprefix\u003e query.\u003cname\u003e \u003csuffix\u003e */`.\nThe prefix and suffix (whitespace, connectives like `AND`/`OR`, separators like\n`,`) are preserved around the substituted value; when the value is empty the\nwhole sentinel is dropped.\n\n```go\ntype User struct {\n    ID   int    `db:\"id\"`\n    Name string `db:\"name\"`\n    Role string `db:\"role\"`\n}\n\nrows, err := pool.Query(ctx,\n    `SELECT id, name, role\n       FROM users\n      WHERE tenant_id = $1\n        /* AND query.where */\n      ORDER BY id\n        /* , query.order_by */`,\n    \u0026pgxquery.QueryRewriter{\n        Where:   \"role = 'admin'\",\n        OrderBy: \"name asc\",\n        Args:    []any{42},\n    },\n)\n```\n\nRecognised sentinel names are `where` and `order_by`. `Args` are appended to\nthe positional parameters passed to `pool.Query` — so the `$1` above is filled\nfrom `Args[0]`. When `Where` or `OrderBy` is empty, its sentinel is stripped\nentirely, leaving the surrounding SQL valid.\n\n`$N` placeholders inside `Where` and `OrderBy` use **local numbering**: `$1`\nrefers to `Args[0]`, `$2` to `Args[1]`, and so on. The rewriter shifts them\nby the count of base args so they hit the right slots in the final flat\nparameter list. Placeholders inside string literals, quoted identifiers,\ndollar-quoted bodies and SQL comments are left untouched.\n\n## Development\n\n### DevContainer\n\nOpen in VS Code with the Dev Containers extension. The environment provides Go,\nPostgreSQL 18, and Nix automatically.\n\n```\nPGX_DATABASE_URL=postgres://vscode@postgres:5432/pgxquery?sslmode=disable\n```\n\n### Nix\n\n```bash\nnix develop          # enter shell with Go\ngo tool ginkgo run -r\n```\n\n### Run tests\n\n```bash\n# Unit tests only (no database required)\ngo tool ginkgo run -r\n\n# With integration tests\nexport PGX_DATABASE_URL=\"postgres://localhost/pgxquery?sslmode=disable\"\ngo tool ginkgo run -r\n```\n\n## License\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpgx-contrib%2Fpgxquery","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpgx-contrib%2Fpgxquery","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpgx-contrib%2Fpgxquery/lists"}