Connect Workers to PostgreSQL/MySQL with Hyperdrive's global pooling and caching. Use when: connecting to existing databases, setting up connection pools, using node-postgres/mysql2, integrating Drizzle/Prisma, or troubleshooting pool acquisition failures, TLS errors, nodejs_compat missing, or eval() disallowed.
Complete knowledge domain for Cloudflare Hyperdrive - Connect Cloudflare Workers to existing PostgreSQL and MySQL databases with global connection pooling, query caching, and reduced latency.
This skill provides complete Hyperdrive knowledge including:
| Issue | Description | Prevention | |-------|-------------|------------| | "nodejs_compat" flag missing | Worker crashes with "No such module" error | Always include nodejs_compat in compatibility_flags | | TLS not supported error (2012) | Database doesn't have SSL enabled | Ensure database has TLS/SSL enabled before creating Hyperdrive config | | Connection refused (2011) | Firewall blocking Hyperdrive | Allow public internet connections or use Cloudflare Tunnel | | Failed to acquire connection | Connection pool exhausted | Use ctx.waitUntil() for cleanup, avoid long-running transactions | | mysql2 eval() error | mysql2 uses eval() which is blocked | Set disableEval: true in mysql2 connection config | | Connection limit exceeded | Workers limit: 6 concurrent connections | Set max: 5 for pg.Pool to stay within limits | | Queries not cached | postgres.js configured with prepare: false | Enable prepared statements with prepare: true | | Invalid credentials (2013) | Username or password incorrect | Verify credentials are correct (case-sensitive password) | | Private IP not supported (2009) | Trying to connect to 192.168.x.x or 10.x.x.x | Use Cloudflare Tunnel for private database access | | Database doesn't exist (2014) | Wrong database name in connection string | Verify database (not table) name exists |
import { Client } from "pg";
type Bindings = {
HYPERDRIVE: Hyperdrive;
};
export default {
async fetch(request: Request, env: Bindings, ctx: ExecutionContext) {
// Connect to PostgreSQL via Hyperdrive
const client = new Client({
connectionString: env.HYPERDRIVE.connectionString
});
await client.connect();
try {
// Query your database
const result = await client.query('SELECT * FROM users LIMIT 10');
return Response.json({
users: result.rows,
// Hyperdrive metadata
origin: env.HYPERDRIVE.host,
cacheStatus: request.cf?.cacheStatus
});
} finally {
// Clean up connection after response is sent
ctx.waitUntil(client.end());
}
}
};
wrangler.jsonc:
{
"name": "my-worker",
"main": "src/index.ts",
"compatibility_date": "2024-09-23",
"compatibility_flags": ["nodejs_compat"],
"hyperdrive": [
{
"binding": "HYPERDRIVE",
"id": "<your-hyperdrive-id>"
}
]
}
Create Hyperdrive config:
npx wrangler hyperdrive create my-database \
--connection-string="postgres://user:password@host:5432/database"
Without this skill:
With this skill:
PostgreSQL: AWS RDS/Aurora, Google Cloud SQL, Azure Database, Neon, Supabase, PlanetScale, Timescale, CockroachDB, Materialize, Fly.io, pgEdge, Prisma Postgres
MySQL: AWS RDS/Aurora, Google Cloud SQL, Azure Database, PlanetScale
Use this skill when you see keywords like:
npx skills add ovachiever/cloudflare-hyperdrive下载完整 Skill 目录,包含 SKILL.md 及所有相关文件
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer