cloudflare-hyperdrive
Cloudflare Hyperdrive for Workers-to-database connections with pooling and caching. Use for PostgreSQL/MySQL, Drizzle/Prisma, or encountering pool errors, TLS issues, connection refused.
What this skill does
# Cloudflare Hyperdrive
**Status**: Production Ready ✅ | **Last Verified**: 2025-11-18
---
## What Is Hyperdrive?
Connect Workers to existing PostgreSQL/MySQL databases:
- Global connection pooling
- Query caching
- Reduced latency
- Works with node-postgres, postgres.js, mysql2
---
## Quick Start (5 Minutes)
### 1. Create Hyperdrive Config
```bash
bunx wrangler hyperdrive create my-db \
--connection-string="postgres://user:pass@host:5432/database"
```
Save the `id`!
### 2. Configure Binding
```jsonc
{
"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>"
}
]
}
```
### 3. Install Driver
```bash
bun add pg # or postgres, or mysql2
```
### 4. Query Database
```typescript
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.**
---
## Critical Rules
### Always Do ✅
1. **Enable nodejs_compat** flag (required!)
2. **Use env.HYPERDRIVE.connectionString** (not original DB string)
3. **Close connections** after queries
4. **Handle errors** explicitly
5. **Use connection pooling** (built-in)
6. **Test locally** with wrangler dev
7. **Monitor query performance**
8. **Use prepared statements**
9. **Enable query caching** (automatic)
10. **Secure connection strings** (use secrets)
### Never Do ❌
1. **Never skip nodejs_compat** (drivers won't work)
2. **Never use original DB connection string** in Workers
3. **Never leave connections open** (pool exhaustion)
4. **Never skip error handling** (DB can fail)
5. **Never hardcode credentials** in code
6. **Never exceed connection limits**
7. **Never use eval/Function** (blocked in Workers)
8. **Never skip TLS** for production DBs
9. **Never use blocking queries** (Worker timeout)
10. **Never expose DB errors** to users
---
## Database Drivers
### PostgreSQL (node-postgres)
```typescript
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();
```
### PostgreSQL (postgres.js)
```typescript
import postgres from 'postgres';
const sql = postgres(env.HYPERDRIVE.connectionString);
const users = await sql`SELECT * FROM users`;
```
### MySQL
```typescript
import mysql from 'mysql2/promise';
const connection = await mysql.createConnection(env.HYPERDRIVE.connectionString);
const [rows] = await connection.execute('SELECT * FROM users');
await connection.end();
```
---
## With Drizzle ORM
```typescript
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();
```
---
## Common Use Cases
### Use Case 1: Read-Only Queries
```typescript
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);
}
};
```
### Use Case 2: Parameterized Queries
```typescript
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();
```
### Use Case 3: Transactions
```typescript
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();
}
```
---
## Supported Databases
**PostgreSQL:**
- Amazon RDS
- Amazon Aurora
- Neon
- Supabase
- Railway
- Render
- DigitalOcean
- Any PostgreSQL 11+
**MySQL:**
- Amazon RDS
- Amazon Aurora
- PlanetScale
- Any MySQL 5.7+
---
## Official Documentation
- **Hyperdrive Overview**: https://developers.cloudflare.com/hyperdrive/
- **Get Started**: https://developers.cloudflare.com/hyperdrive/get-started/
- **Configuration**: https://developers.cloudflare.com/hyperdrive/configuration/
---
## Bundled Resources
**References** (`references/`):
- `setup-guide.md` - Complete setup walkthrough (create config, bind, query)
- `connection-pooling.md` - Connection pool configuration and best practices
- `query-caching.md` - Query caching strategies and optimization
- `drizzle-integration.md` - Drizzle ORM integration patterns
- `prisma-integration.md` - Prisma ORM integration patterns
- `supported-databases.md` - Complete list of supported PostgreSQL and MySQL providers
- `tls-ssl-setup.md` - TLS/SSL configuration for secure connections
- `troubleshooting.md` - Common issues and solutions
- `wrangler-commands.md` - Complete wrangler CLI commands for Hyperdrive
**Templates** (`templates/`):
- `postgres-basic.ts` - Basic PostgreSQL with node-postgres
- `postgres-js.ts` - PostgreSQL with postgres.js driver
- `postgres-pool.ts` - PostgreSQL with connection pooling
- `mysql2-basic.ts` - MySQL with mysql2 driver
- `drizzle-postgres.ts` - Drizzle ORM with PostgreSQL
- `drizzle-mysql.ts` - Drizzle ORM with MySQL
- `prisma-postgres.ts` - Prisma ORM with PostgreSQL
- `local-dev-setup.sh` - Local development setup script
- `wrangler-hyperdrive-config.jsonc` - Wrangler configuration example
---
**Questions? Issues?**
1. Check `references/setup-guide.md` for complete setup
2. Verify nodejs_compat flag enabled
3. Ensure using env.HYPERDRIVE.connectionString
4. Check connection properly closed
Related in Cloud & DevOps
appbuilder-action-scaffolder
IncludedCreate, implement, deploy, and debug Adobe Runtime actions with consistent layout, validation, and error handling. Use this skill whenever the user needs to add actions to an App Builder project, understand action structure (params, response format, web/raw actions), configure actions in the manifest, use App Builder SDKs (State, Files, Events, database), deploy and invoke actions via CLI, debug action issues, or implement patterns such as webhook receivers, custom event providers, journaling consumers, large payload redirects, action sequence pipelines, and Asset Compute workers. Also trigger when users mention serverless functions in Adobe context, action logging, IMS authentication for actions, or cron-style scheduled actions.
orchestrating-datacloud
IncludedSalesforce Data Cloud product orchestrator for connect→prepare→harmonize→segment→act workflows. Use this skill when the user needs a multi-step Data Cloud pipeline, cross-phase troubleshooting, or data space and data kit management. TRIGGER when: user needs a multi-step Data Cloud pipeline, asks to set up or troubleshoot Data Cloud across phases, manages data spaces or data kits, or wants a cross-phase sf data360 workflow. DO NOT TRIGGER when: work is isolated to a single phase (use the matching phase-specific skill), the task is STDM/session tracing/parquet telemetry (use observing-agentforce), standard CRM SOQL (use querying-soql), or Apex implementation (use generating-apex).
github-project-automation
IncludedAutomate GitHub repository setup with CI/CD workflows, issue templates, Dependabot, and CodeQL security scanning. Includes 12 production-tested workflows and prevents 18 errors: YAML syntax, action pinning, and configuration. Use when: setting up GitHub Actions CI/CD, creating issue/PR templates, enabling Dependabot or CodeQL scanning, deploying to Cloudflare Workers, implementing matrix testing, or troubleshooting YAML indentation, action version pinning, secrets syntax, runner versions, or CodeQL configuration. Keywords: github actions, github workflow, ci/cd, issue templates, pull request templates, dependabot, codeql, security scanning, yaml syntax, github automation, repository setup, workflow templates, github actions matrix, secrets management, branch protection, codeowners, github projects, continuous integration, continuous deployment, workflow syntax error, action version pinning, runner version, github context, yaml indentation error
sf-datacloud
IncludedSalesforce Data Cloud product orchestrator for connect→prepare→harmonize→segment→act workflows. TRIGGER when: user needs a multi-step Data Cloud pipeline, asks to set up or troubleshoot Data Cloud across phases, manages data spaces or data kits, or wants a cross-phase `sf data360` workflow. DO NOT TRIGGER when: work is isolated to a single phase (use the matching sf-datacloud-* skill), the task is STDM/session tracing/parquet telemetry (use sf-ai-agentforce-observability), standard CRM SOQL (use sf-soql), or Apex implementation (use sf-apex).
fabric-cli
IncludedUse this skill for Fabric.so CLI workflows with the `fabric` terminal command: diagnose/install/login, search or browse a Fabric library, save notes/links/files, create folders, ask the Fabric AI assistant, manage tasks/workspaces, generate shell completion, check subscription usage, produce JSON output, and use Fabric as persistent agent memory. Do not use for Microsoft Fabric/Azure/Power BI `fab`, Daniel Miessler's Fabric framework, Python Fabric SSH, Fabric.js, or textile/fashion fabric.
lark
IncludedLark/Feishu CLI skills: lark-cli operations for docs, markdown, sheets, base, calendar, im, mail, task, okr, drive, wiki, slides, whiteboard, apps, approval, attendance, contact, vc, minutes, event. Use when the user needs to operate Lark/Feishu resources via lark-cli, send messages, manage documents, spreadsheets, calendars, tasks, OKRs, deploy web pages, or any Feishu/Lark workspace operations.