{"id":15715439,"url":"https://github.com/cloudflare/worker-template-postgres","last_synced_at":"2025-03-23T14:09:10.752Z","repository":{"id":40700669,"uuid":"424346653","full_name":"cloudflare/worker-template-postgres","owner":"cloudflare","description":"Reference demo and modified PostgreSQL driver to connect Cloudflare Workers to a relational database.","archived":false,"fork":false,"pushed_at":"2024-09-25T03:15:17.000Z","size":368,"stargazers_count":86,"open_issues_count":4,"forks_count":15,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-15T11:05:18.522Z","etag":null,"topics":["cloudflare","database","postgres","serverless","sql","workers"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cloudflare.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE_APACHE","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2021-11-03T19:00:06.000Z","updated_at":"2025-02-12T21:15:39.000Z","dependencies_parsed_at":"2024-12-24T12:13:47.679Z","dependency_job_id":"b21c60e8-2a7b-4d6d-8fa9-00f387dd7d99","html_url":"https://github.com/cloudflare/worker-template-postgres","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudflare%2Fworker-template-postgres","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudflare%2Fworker-template-postgres/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudflare%2Fworker-template-postgres/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudflare%2Fworker-template-postgres/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cloudflare","download_url":"https://codeload.github.com/cloudflare/worker-template-postgres/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244952776,"owners_count":20537472,"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","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":["cloudflare","database","postgres","serverless","sql","workers"],"created_at":"2024-10-03T21:41:34.947Z","updated_at":"2025-03-23T14:09:10.730Z","avatar_url":"https://github.com/cloudflare.png","language":"JavaScript","readme":"# Cloudflare Workers + PostgreSQL\n\nThis repo contains example code and a PostgreSQL driver that can be used in any Workers project. If\nyou are interested in using the driver _outside_ of this template, copy the `driver/postgres` module\ninto your project's `node_modules` or directly alongside your source.\n\n## Usage\n\nBefore you start, please refer to the **[official tutorial](https://developers.cloudflare.com/workers/tutorials/query-postgres-from-workers-using-database-connectors)**.\n\n```typescript\nconst client = new Client({\n    user: '\u003cDATABASE_USER\u003e',\n    database: '\u003cDATABASE_NAME\u003e',\n    // hostname is the full URL to your pre-created Cloudflare Tunnel, see documentation here:\n    // https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/create-tunnel\n    hostname: env.TUNNEL_HOST || 'https://dev.example.com',\n    password: env.DATABASE_PASSWORD, // use a secret to store passwords\n    port: '\u003cDATABASE_PORT\u003e',\n})\n\nawait client.connect()\n```\n\n**Please Note:**\n- you must use this config object format vs. a database connection string\n- the `hostname` property must be the URL to your Cloudflare Tunnel, _NOT_ your database host\n    - your Tunnel will be configured to connect to your database host\n\n## Running the Postgres Demo\n\n`postgres/docker-compose.yml`\n\nThis docker-compose composition will get you up and running with a local instance of `postgresql`, \n`pgbouncer` in front to provide connection pooling, and a copy of `cloudflared` to enable your \napplications to securely connect, through a encrypted tunnel, without opening any ports up locally.\n\n### Usage\n\n\u003e from within `scripts/postgres`, run: \n\n1. **Create credentials file (first time only)**\n```sh\ndocker run -v ~/.cloudflared:/etc/cloudflared cloudflare/cloudflared:2021.10.5 login\n```\n\n2. **Start a local dev stack (cloudflared/pgbouncer/postgres)**\n```sh\nTUNNEL_HOSTNAME=dev.example.com docker-compose up\n```","funding_links":[],"categories":["Templates \u0026 Examples"],"sub_categories":["Starter Templates"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloudflare%2Fworker-template-postgres","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcloudflare%2Fworker-template-postgres","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloudflare%2Fworker-template-postgres/lists"}