{"id":22347647,"url":"https://github.com/pgx-contrib/pgxgcp","last_synced_at":"2026-05-04T03:35:53.704Z","repository":{"id":251225730,"uuid":"836284656","full_name":"pgx-contrib/pgxgcp","owner":"pgx-contrib","description":"Google Cloud SQL connector and query caching backends (Firestore, Datastore, Storage) for pgx v5","archived":false,"fork":false,"pushed_at":"2026-04-29T11:54:52.000Z","size":106,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-04-29T13:40:11.192Z","etag":null,"topics":["cloud-sql","cloud-storage","cloudsql","datastore","firestore","gcp","golang","pgx","pgx-contrib","pgxcache","postgres","postgresql"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/pgx-contrib/pgxgcp","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":"2024-07-31T14:20:46.000Z","updated_at":"2026-04-29T11:54:49.000Z","dependencies_parsed_at":"2024-10-24T14:51:24.265Z","dependency_job_id":"d0d1dcbf-f2ab-4014-8833-0e69906c733d","html_url":"https://github.com/pgx-contrib/pgxgcp","commit_stats":null,"previous_names":["pgx-contrib/pgxgcp"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/pgx-contrib/pgxgcp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgx-contrib%2Fpgxgcp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgx-contrib%2Fpgxgcp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgx-contrib%2Fpgxgcp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgx-contrib%2Fpgxgcp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pgx-contrib","download_url":"https://codeload.github.com/pgx-contrib/pgxgcp/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgx-contrib%2Fpgxgcp/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32593945,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-03T22:12:39.696Z","status":"online","status_checked_at":"2026-05-04T02:00:06.625Z","response_time":58,"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":["cloud-sql","cloud-storage","cloudsql","datastore","firestore","gcp","golang","pgx","pgx-contrib","pgxcache","postgres","postgresql"],"created_at":"2024-12-04T10:10:08.480Z","updated_at":"2026-05-04T03:35:53.698Z","avatar_url":"https://github.com/pgx-contrib.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pgxgcp\n\n[![CI](https://github.com/pgx-contrib/pgxgcp/actions/workflows/ci.yml/badge.svg)](https://github.com/pgx-contrib/pgxgcp/actions/workflows/ci.yml)\n[![Release](https://img.shields.io/github/v/release/pgx-contrib/pgxgcp)](https://github.com/pgx-contrib/pgxgcp/releases)\n[![Go Reference](https://pkg.go.dev/badge/github.com/pgx-contrib/pgxgcp.svg)](https://pkg.go.dev/github.com/pgx-contrib/pgxgcp)\n[![License](https://img.shields.io/github/license/pgx-contrib/pgxgcp)](LICENSE)\n[![Go Version](https://img.shields.io/github/go-mod/go-version/pgx-contrib/pgxgcp)](go.mod)\n[![pgx](https://img.shields.io/badge/pgx-v5-blue)](https://github.com/jackc/pgx)\n[![GCP](https://img.shields.io/badge/GCP-Cloud_SQL-4285F4)](https://cloud.google.com/sql)\n\nGoogle Cloud integration for [pgx v5](https://github.com/jackc/pgx), supporting Cloud SQL connections via the Cloud SQL Connector, plus query caching backends using Firestore, Datastore, and Cloud Storage.\n\n## Features\n\n- **Cloud SQL Connector** — connect to Cloud SQL instances via `pgx.ConnConfig.BeforeConnect` using the Cloud SQL Proxy dialer\n- **FirestoreQueryCacher** — query result caching backed by Google Firestore (implements [pgxcache](https://github.com/pgx-contrib/pgxcache))\n- **DatastoreQueryCacher** — query result caching backed by Google Datastore (implements [pgxcache](https://github.com/pgx-contrib/pgxcache))\n- **StorageQueryCacher** — query result caching backed by Google Cloud Storage (implements [pgxcache](https://github.com/pgx-contrib/pgxcache))\n\n## Installation\n\n```bash\ngo get github.com/pgx-contrib/pgxgcp\n```\n\n## Usage\n\n### Connector (Cloud SQL)\n\nThe `Connector` uses the Cloud SQL Proxy dialer to connect to Cloud SQL instances. It hooks into `pgx.ConnConfig.BeforeConnect` and replaces the dial function when `GOOGLE_APPLICATION_CREDENTIALS` is set.\n\n```go\nconfig, err := pgxpool.ParseConfig(os.Getenv(\"PGX_DATABASE_URL\"))\nif err != nil {\n    panic(err)\n}\n\nctx := context.TODO()\n// Create a new pgxgcp.Connector\nconnector, err := pgxgcp.Connect(ctx)\nif err != nil {\n    panic(err)\n}\n\n// Set BeforeConnect hook to connector.BeforeConnect\nconfig.BeforeConnect = connector.BeforeConnect\n\n// Create a new pgxpool with the config\nconn, err := pgxpool.NewWithConfig(ctx, config)\nif err != nil {\n    panic(err)\n}\n\nrows, err := conn.Query(ctx, \"SELECT * from organization\")\nif err != nil {\n    panic(err)\n}\ndefer rows.Close()\n\ntype Organization struct {\n    Name string `db:\"name\"`\n}\n\nfor rows.Next() {\n    organization, err := pgx.RowToStructByName[Organization](rows)\n    if err != nil {\n        panic(err)\n    }\n    fmt.Println(organization.Name)\n}\n```\n\n### FirestoreQueryCacher\n\nCache query results in Google Firestore using [pgxcache](https://github.com/pgx-contrib/pgxcache):\n\n```go\n// Create a new client\nclient, err := firestore.NewClient(context.TODO(), os.Getenv(\"GOOGLE_PROJECT_ID\"))\nif err != nil {\n    panic(err)\n}\n\n// Create a new cacher\ncacher := \u0026pgxgcp.FirestoreQueryCacher{\n    Client:     client,\n    Collection: \"queries\",\n}\n\n// create a new querier\nquerier := \u0026pgxcache.Querier{\n    Options: \u0026pgxcache.QueryOptions{\n        MaxLifetime: 30 * time.Second,\n        MaxRows:     1,\n    },\n    Cacher:  cacher,\n    Querier: conn,\n}\n\nrows, err := querier.Query(context.TODO(), \"SELECT * from customer\")\n```\n\n### DatastoreQueryCacher\n\nCache query results in Google Datastore using [pgxcache](https://github.com/pgx-contrib/pgxcache):\n\n```go\n// Create a new client\nclient, err := datastore.NewClient(context.TODO(), os.Getenv(\"GOOGLE_PROJECT_ID\"))\nif err != nil {\n    panic(err)\n}\n\n// Create a new cacher\ncacher := \u0026pgxgcp.DatastoreQueryCacher{\n    Client: client,\n    Kind:   \"queries\",\n}\n\n// create a new querier\nquerier := \u0026pgxcache.Querier{\n    Options: \u0026pgxcache.QueryOptions{\n        MaxLifetime: 30 * time.Second,\n        MaxRows:     1,\n    },\n    Cacher:  cacher,\n    Querier: conn,\n}\n\nrows, err := querier.Query(context.TODO(), \"SELECT * from customer\")\n```\n\n### StorageQueryCacher\n\nCache query results in Google Cloud Storage using [pgxcache](https://github.com/pgx-contrib/pgxcache):\n\n```go\n// Create a new client\nclient, err := storage.NewClient(context.TODO())\nif err != nil {\n    panic(err)\n}\n\n// Create a new cacher\ncacher := \u0026pgxgcp.StorageQueryCacher{\n    Client: client,\n    Bucket: \"queries\",\n}\n\n// create a new querier\nquerier := \u0026pgxcache.Querier{\n    Options: \u0026pgxcache.QueryOptions{\n        MaxLifetime: 30 * time.Second,\n        MaxRows:     1,\n    },\n    Cacher:  cacher,\n    Querier: conn,\n}\n\nrows, err := querier.Query(context.TODO(), \"SELECT * from customer\")\n```\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/pgxgcp?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/pgxgcp?sslmode=disable\"\ngo tool ginkgo run -r\n```\n\nIntegration tests require real GCP infrastructure and are guarded by environment variables — they are skipped automatically when the variables are not set:\n\n| Variable | Used by |\n|----------|---------|\n| `PGXGCP_CLOUD_SQL_INSTANCE` | `Connector` (e.g. `project:region:instance`) |\n| `GOOGLE_PROJECT_ID` | `FirestoreQueryCacher`, `DatastoreQueryCacher` |\n| `PGXGCP_FIRESTORE_COLLECTION` | `FirestoreQueryCacher` |\n| `PGXGCP_DATASTORE_KIND` | `DatastoreQueryCacher` |\n| `PGXGCP_STORAGE_BUCKET` | `StorageQueryCacher` |\n\n## License\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpgx-contrib%2Fpgxgcp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpgx-contrib%2Fpgxgcp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpgx-contrib%2Fpgxgcp/lists"}