{"id":50812749,"url":"https://github.com/pgx-contrib/pgxaip","last_synced_at":"2026-06-13T06:33:44.383Z","repository":{"id":353560921,"uuid":"1218160496","full_name":"pgx-contrib/pgxaip","owner":"pgx-contrib","description":"Drop-in pgx v5 query rewriter that turns AIP-160 filter and AIP-132 order-by strings into parameterized WHERE and ORDER BY clauses.","archived":false,"fork":false,"pushed_at":"2026-06-04T03:48:26.000Z","size":65,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-04T05:25:10.841Z","etag":null,"topics":["aip","aip-132","aip-160","filtering","go","golang","pgx","postgres","postgresql","query-rewriter","sql"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/pgx-contrib/pgxaip","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-22T15:38:12.000Z","updated_at":"2026-06-04T03:48:22.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/pgx-contrib/pgxaip","commit_stats":null,"previous_names":["pgx-contrib/pgxquery"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/pgx-contrib/pgxaip","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgx-contrib%2Fpgxaip","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgx-contrib%2Fpgxaip/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgx-contrib%2Fpgxaip/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgx-contrib%2Fpgxaip/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pgx-contrib","download_url":"https://codeload.github.com/pgx-contrib/pgxaip/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgx-contrib%2Fpgxaip/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":["aip","aip-132","aip-160","filtering","go","golang","pgx","postgres","postgresql","query-rewriter","sql"],"created_at":"2026-06-13T06:33:43.828Z","updated_at":"2026-06-13T06:33:44.369Z","avatar_url":"https://github.com/pgx-contrib.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pgxaip\n\n[![CI](https://github.com/pgx-contrib/pgxaip/actions/workflows/ci.yml/badge.svg)](https://github.com/pgx-contrib/pgxaip/actions/workflows/ci.yml)\n[![Release](https://img.shields.io/github/v/release/pgx-contrib/pgxaip?include_prereleases)](https://github.com/pgx-contrib/pgxaip/releases)\n[![Go Reference](https://pkg.go.dev/badge/github.com/pgx-contrib/pgxaip.svg)](https://pkg.go.dev/github.com/pgx-contrib/pgxaip)\n[![License](https://img.shields.io/github/license/pgx-contrib/pgxaip)](LICENSE)\n[![Go](https://img.shields.io/badge/Go-1.25-00ADD8?logo=go\u0026logoColor=white)](https://go.dev)\n\n`pgxaip` rewrites a parsed [AIP-160](https://google.aip.dev/160) filter,\nan [AIP-132](https://google.aip.dev/132#ordering) `order_by`, and an\noptional keyset cursor into Postgres SQL fragments you splice into a\nquery by hand.\n\n```go\nquery := pgxaip.Query{\n    Filter:    filter,     // from filtering.ParseFilter\n    OrderBy:   orderBy,    // from ordering.ParseOrderBy\n    PageToken: pageToken,  // from pagination.ParsePageToken (incl. Cursor)\n    Columns:   columns,    // AIP path -\u003e DB column\n}\n\nwhere, order, args, err := query.Rewrite()\n```\n\n- `where` — the WHERE predicate (filter, cursor, or both ANDed). Empty\n  when neither is present.\n- `order` — the `col ASC, col DESC` list, no `ORDER BY` prefix. Empty\n  when `OrderBy` has no fields.\n- `args` — positional bind values, numbered `$1..$N`. Filter literals\n  first, then cursor values. Append your own `LIMIT` / `OFFSET` at\n  `$N+1`.\n\n`PageToken.Offset` is not consulted by `Rewrite`; feed it into your\n`OFFSET` clause yourself.\n\n## Installation\n\n```bash\ngo get github.com/pgx-contrib/pgxaip\n```\n\n## Usage\n\n```go\nfilter, _ := filtering.ParseFilter(req, BookFilterDeclarations)\norderBy, _ := ordering.ParseOrderBy(req)\npageToken, _ := pagination.ParsePageToken(req)\n\n// Unified column map: union of the generated *FilterColumns and\n// *OrderByColumns. Same path -\u003e same column by construction, so the\n// union is safe.\ncolumns := map[string]string{}\nfor k, v := range BookFilterColumns {\n    columns[k] = v\n}\nfor k, v := range BookOrderByColumns {\n    columns[k] = v\n}\n\nq := pgxaip.Query{\n    Filter:    filter,\n    OrderBy:   orderBy,\n    PageToken: pageToken,\n    Columns:   columns,\n}\nwhere, order, args, err := q.Rewrite()\n```\n\n`Columns` is the AIP-path → DB-column allow-list. Lookup is\n**fail-closed**: any filter / order / cursor path that is not in\n`Columns` causes `Rewrite` to return an error, so an unmapped field\ncan never leak into generated SQL. Pair with the `*FilterColumns` /\n`*OrderByColumns` maps produced by\n[`protoc-gen-go-aip-query`](https://github.com/protoc-contrib/protoc-gen-go-aip-query)\nor hand-build a `map[string]string` for ad-hoc use.\n\n## Filter operators\n\n| AIP filter                          | Postgres fragment                     |\n| ----------------------------------- | ------------------------------------- |\n| `=, !=, \u003c, \u003c=, \u003e, \u003e=`               | `col op $N` (or `col op col`)         |\n| `AND`, `OR`                         | `(lhs AND rhs)` / `(lhs OR rhs)`      |\n| `NOT`                               | `(NOT expr)`                          |\n| `name:\"ali\"`                        | `\"name\" ILIKE '%' \\|\\| $N \\|\\| '%'`   |\n| `timestamp(\"2025-01-02T03:04:05Z\")` | `$N` bound as `time.Time`             |\n| `duration(\"1h30m\")`                 | `$N` bound as `time.Duration`         |\n| unary `-\u003cliteral\u003e`                  | bound as signed numeric literal       |\n\n## Cursor pagination\n\nWhen `PageToken.Cursor` is populated, `Rewrite` emits the standard\ncompound keyset predicate from `OrderBy.Fields`:\n\n```sql\n(\"name\" \u003c $1)\n  OR (\"name\" = $1 AND \"id\" \u003e $2)\n```\n\nDirection per field follows the `OrderBy` field's `Desc` flag\n(ASC → `\u003e`, DESC → `\u003c`). `len(PageToken.Cursor)` must equal\n`len(OrderBy.Fields)`; mismatch is a validation error.\n\nFor a stable ordering, append a tiebreaker (the PK) to\n`OrderBy.Fields` before calling `Rewrite`, and make sure\n`PageToken.Cursor` carries a matching trailing value.\n\nOn the first page (`PageToken.Cursor` is empty) the cursor predicate\nis omitted.\n\n## Development\n\n```bash\nnix develop\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%2Fpgxaip","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpgx-contrib%2Fpgxaip","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpgx-contrib%2Fpgxaip/lists"}