Cloudflare Hyperdrive
Reylo on Postgres and MySQL through Hyperdrive
Reylo runs in a Worker on Postgres and MySQL through Hyperdrive, Cloudflare's connection pool. Everything on the Postgres and MySQL pages holds through it. Set up the Vite plugin as on Cloudflare D1.
| Postgres | pg, postgres.js or Drizzle Postgres, with the binding's connection string, and Drizzle over pg |
| MySQL | mysql2 or mariadb, with the binding's host, port, user, password and database |
| The type check reads | Your development database, through direct_url, never Hyperdrive |
| Node's APIs | pg, postgres.js, Drizzle Postgres, mysql2 and mariadb need a compatibility date from 2026-08-04 on, or the nodejs_compat flag |
Postgres
Connect with the binding's connection string and close the client with ctx.waitUntil():
import { Client } from "pg";
import getUser from "./get_user.sql";
export default {
async fetch(request: Request, env: { HYPERDRIVE: Hyperdrive }, ctx: ExecutionContext) {
const client = new Client({ connectionString: env.HYPERDRIVE.connectionString });
await client.connect();
const user = await getUser.run(client, { id: 1 });
ctx.waitUntil(client.end());
return Response.json(user);
},
};import { connect } from "drizzle-orm/postgres/client";
import getUser from "./get_user.sql";
export default {
async fetch(request: Request, env: { HYPERDRIVE: Hyperdrive }, ctx: ExecutionContext) {
const client = await connect({ url: env.HYPERDRIVE.connectionString });
const user = await getUser.run(client, { id: 1 });
ctx.waitUntil(client.end());
return Response.json(user);
},
};MySQL
Hyperdrive refuses prepared statements. Reylo runs mysql2 through query() with values written into the statement, and runs mariadb without prepared statements everywhere:
import mysql from "mysql2/promise";
import getUser from "./get_user.sql";
export default {
async fetch(request: Request, env: { HYPERDRIVE: Hyperdrive }, ctx: ExecutionContext) {
const { host, port, user, password, database } = env.HYPERDRIVE;
const conn = await mysql.createConnection({
host,
port,
user,
password,
database,
disableEval: true, // required in Workers
});
const row = await getUser.run(conn, { id: 1 });
ctx.waitUntil(conn.end());
return Response.json(row);
},
};import mariadb from "mariadb";
import getUser from "./get_user.sql";
export default {
async fetch(request: Request, env: { HYPERDRIVE: Hyperdrive }, ctx: ExecutionContext) {
const { host, port, user, password, database } = env.HYPERDRIVE;
const conn = await mariadb.createConnection({ host, port, user, password, database });
const row = await getUser.run(conn, { id: 1 });
ctx.waitUntil(conn.end());
return Response.json(row);
},
};