Skip to content

Cloudflare.Hyperdrive reference

Source: src/Cloudflare/Hyperdrive/Connect.ts

A typed accessor for a Cloudflare Hyperdrive runtime binding inside a Worker. Provides the same shape as the raw Hyperdrive runtime object (connection string, host, port, user, password, database) plus a raw escape hatch for libraries that want direct access.

Bind Hyperdrive in a Worker

const hd = yield* Cloudflare.Hyperdrive.Connect(MyConnection);
const url = yield* hd.connectionString;

/ /** Bind a Connection to a Worker and obtain the Effect-native Hyperdrive client (connection string, host, port, …).

Connect is a single identifier that is simultaneously the binding’s Context tag, its type, and the callable — yield* Cloudflare.Hyperdrive.Connect(conn).

Using Hyperdrive inside a Worker

const hd = yield* Cloudflare.Hyperdrive.Connect(MyConnection);
const url = yield* hd.connectionString;

Source: src/Cloudflare/Hyperdrive/Connection.ts

A Cloudflare Hyperdrive configuration.

Hyperdrive accelerates and pools connections to existing PostgreSQL or MySQL databases, exposing them to Workers via a binding. Create a config as a resource, then bind it to a Worker to obtain a connection string.

const hd = yield* Cloudflare.Hyperdrive.Connection("my-pg", {
origin: {
scheme: "postgres",
host: "db.example.com",
port: 5432,
database: "app",
user: "app",
password: yield* Config.Redacted("DB_PASSWORD"),
},
});
const hd = yield* Cloudflare.Hyperdrive.Connect(MyConnection);
const url = yield* hd.connectionString;