Supabase
import { Render } from "~/components";
This example shows you how to connect Hyperdrive to a Supabase Postgres database.
1. Allow Hyperdrive access
You can connect Hyperdrive to any existing Supabase database as the Postgres user which is set up during project creation. Alternatively, to create a new user for Hyperdrive, run these commands in the SQL Editor.
CREATE ROLE hyperdrive_user LOGIN PASSWORD 'sufficientlyRandomPassword';
-- Here, you are granting it the postgres role. In practice, you want to create a role with lesser privileges.
GRANT postgres to hyperdrive_user;
The database endpoint can be found in the database settings page.
With a database user, password, database endpoint (hostname and port) and database name (default: postgres), you can now set up Hyperdrive.
:::note
When connecting to Supabase from Hyperdrive, you should use the Direct connection connection string rather than the pooled connection strings. Hyperdrive will perform pooling of connections to ensure optimal access from Workers.
:::
2. Create a database configuration
:::note
When connecting to a Supabase database with Hyperdrive, you should use a driver like node-postgres (pg) or Postgres.js to connect directly to the underlying database instead of the Supabase JavaScript client. Hyperdrive is optimized for database access for Workers and will perform global connection pooling and fast query routing by connecting directly to your database.
:::
谢谢你的反馈!