**Status**: Production Ready ✅ | **Last Verified**: 2025-11-18
/plugin marketplace add secondsky/claude-skills/plugin install cloudflare-hyperdrive@claude-skillsThis skill inherits all available tools. When active, it can use any tool Claude has access to.
references/connection-pooling.mdreferences/drizzle-integration.mdreferences/prisma-integration.mdreferences/query-caching.mdreferences/setup-guide.mdreferences/supported-databases.mdreferences/tls-ssl-setup.mdreferences/troubleshooting.mdreferences/wrangler-commands.mdscripts/check-versions.shtemplates/drizzle-mysql.tstemplates/drizzle-postgres.tstemplates/local-dev-setup.shtemplates/mysql2-basic.tstemplates/postgres-basic.tstemplates/postgres-js.tstemplates/postgres-pool.tstemplates/prisma-postgres.tstemplates/wrangler-hyperdrive-config.jsoncStatus: Production Ready ✅ | Last Verified: 2025-11-18
Connect Workers to existing PostgreSQL/MySQL databases:
bunx wrangler hyperdrive create my-db \
--connection-string="postgres://user:pass@host:5432/database"
Save the id!
{
"name": "my-worker",
"main": "src/index.ts",
"compatibility_date": "2024-09-23",
"compatibility_flags": ["nodejs_compat"], // REQUIRED!
"hyperdrive": [
{
"binding": "HYPERDRIVE",
"id": "<ID_FROM_STEP_1>"
}
]
}
bun add pg # or postgres, or mysql2
import { Client } from 'pg';
export default {
async fetch(request, env, ctx) {
const client = new Client({ connectionString: env.HYPERDRIVE.connectionString });
await client.connect();
const result = await client.query('SELECT * FROM users LIMIT 10');
await client.end();
return Response.json(result.rows);
}
};
Load references/setup-guide.md for complete walkthrough.
import { Client } from 'pg';
const client = new Client({ connectionString: env.HYPERDRIVE.connectionString });
await client.connect();
const result = await client.query('SELECT * FROM users');
await client.end();
import postgres from 'postgres';
const sql = postgres(env.HYPERDRIVE.connectionString);
const users = await sql`SELECT * FROM users`;
import mysql from 'mysql2/promise';
const connection = await mysql.createConnection(env.HYPERDRIVE.connectionString);
const [rows] = await connection.execute('SELECT * FROM users');
await connection.end();
import { drizzle } from 'drizzle-orm/node-postgres';
import { Client } from 'pg';
const client = new Client({ connectionString: env.HYPERDRIVE.connectionString });
await client.connect();
const db = drizzle(client);
const users = await db.select().from(usersTable);
await client.end();
export default {
async fetch(request, env, ctx) {
const client = new Client({ connectionString: env.HYPERDRIVE.connectionString });
await client.connect();
const users = await client.query('SELECT * FROM users WHERE active = true');
await client.end();
return Response.json(users.rows);
}
};
const userId = new URL(request.url).searchParams.get('id');
const client = new Client({ connectionString: env.HYPERDRIVE.connectionString });
await client.connect();
const result = await client.query(
'SELECT * FROM users WHERE id = $1',
[userId]
);
await client.end();
const client = new Client({ connectionString: env.HYPERDRIVE.connectionString });
await client.connect();
try {
await client.query('BEGIN');
await client.query('UPDATE accounts SET balance = balance - 100 WHERE id = $1', [1]);
await client.query('UPDATE accounts SET balance = balance + 100 WHERE id = $1', [2]);
await client.query('COMMIT');
} catch (e) {
await client.query('ROLLBACK');
throw e;
} finally {
await client.end();
}
PostgreSQL:
MySQL:
References (references/):
setup-guide.md - Complete setup walkthrough (create config, bind, query)connection-pooling.md - Connection pool configuration and best practicesquery-caching.md - Query caching strategies and optimizationdrizzle-integration.md - Drizzle ORM integration patternsprisma-integration.md - Prisma ORM integration patternssupported-databases.md - Complete list of supported PostgreSQL and MySQL providerstls-ssl-setup.md - TLS/SSL configuration for secure connectionstroubleshooting.md - Common issues and solutionswrangler-commands.md - Complete wrangler CLI commands for HyperdriveTemplates (templates/):
postgres-basic.ts - Basic PostgreSQL with node-postgrespostgres-js.ts - PostgreSQL with postgres.js driverpostgres-pool.ts - PostgreSQL with connection poolingmysql2-basic.ts - MySQL with mysql2 driverdrizzle-postgres.ts - Drizzle ORM with PostgreSQLdrizzle-mysql.ts - Drizzle ORM with MySQLprisma-postgres.ts - Prisma ORM with PostgreSQLlocal-dev-setup.sh - Local development setup scriptwrangler-hyperdrive-config.jsonc - Wrangler configuration exampleQuestions? Issues?
references/setup-guide.md for complete setupUse when working with Payload CMS projects (payload.config.ts, collections, fields, hooks, access control, Payload API). Use when debugging validation errors, security issues, relationship queries, transactions, or hook behavior.