Skip to content

thomasgauvin/postgres-hyperdrive-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Worker + PostgreSQL using Hyperdrive

Hyperdrive makes connecting to your regional database from Cloudflare Workers fast. This project demonstrates a Worker connecting to a PostgreSQL database using Hyperdrive.

Upon loading your Worker, your will see the list of PostgreSQL tables in your database, as obtained with the following query:

SELECT * FROM pg_tables LIMIT 10;

Important

When using C3 to create this project, select "no" when it asks if you want to deploy. You need to follow this project's setup steps before deploying.

Getting Started

Outside of this repo, you can start a new project with this template using C3 (the create-cloudflare CLI):

npm create cloudflare@latest -- --template=cloudflare/templates/postgres-hyperdrive-template

A live public deployment of this template is available at https://postgres-hyperdrive-template.templates.workers.dev

Setup Steps

  1. Install the project dependencies with a package manager of your choice:
    npm install
  2. Create a Hyperdrive configuration with the name "hyperdrive-configuration":
    npx wrangler hyperdrive create hyperdrive-configuration --connection-string="postgres://<DB_USER>:<DB_PASSWORD>@<DB_HOSTNAME_OR_IP_ADDRESS>:5432/<DATABASE_NAME>"
    ...and update the hyperdrive id field in wrangler.json with the new Hyperdrive ID. You can also specify a connection string for a local PostgreSQL database used for development using the hyperdrive localConnectionString field.
  3. Deploy the project!
    npx wrangler deploy

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published