본문으로 건너뛰기
cccskills
무료GitHub에 공개

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.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

설치 방법 보기

포함된 파일(20)

  • SKILL.md7.2 KB
  • references/connection-pooling.md11.5 KB
  • references/drizzle-integration.md12.2 KB
  • references/prisma-integration.md12.8 KB
  • references/query-caching.md12.2 KB
  • references/setup-guide.md2.6 KB
  • references/supported-databases.md11.1 KB
  • references/tls-ssl-setup.md10.5 KB
  • references/troubleshooting.md13.3 KB
  • references/wrangler-commands.md10.6 KB
  • scripts/check-versions.sh3.4 KB
  • templates/drizzle-mysql.ts2.2 KB
  • templates/drizzle-postgres.ts2.1 KB
  • templates/local-dev-setup.sh2.4 KB
  • templates/mysql2-basic.ts2.0 KB
  • templates/postgres-basic.ts1.7 KB
  • templates/postgres-js.ts2.6 KB
  • templates/postgres-pool.ts2.4 KB
  • templates/prisma-postgres.ts3.3 KB
  • templates/wrangler-hyperdrive-config.jsonc1.0 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

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

bunx wrangler hyperdrive create my-db \
  --connection-string="postgres://user:pass@host:5432/database"

Save the id!

2. Configure Binding

{
  "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

bun add pg  # or postgres, or mysql2

4. Query Database

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)

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)

import postgres from 'postgres';

const sql = postgres(env.HYPERDRIVE.connectionString);
const users = await sql`SELECT * FROM users`;

MySQL

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

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

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

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

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


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

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

100+ animated React components (Aceternity UI) for Next.js with Tailwind. Use for hero sections, parallax, 3D effects, or encountering animation, shadcn CLI integration errors.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

secondsky/claude-skills2312026년 10월 20일 업데이트

Secure API authentication with JWT, OAuth 2.0, API keys. Use for authentication systems, third-party integrations, service-to-service communication, or encountering token management, security headers, auth flow errors.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

secondsky/claude-skills2312026년 10월 20일 업데이트

Creates comprehensive API changelogs documenting breaking changes, deprecations, and migration strategies for API consumers. Use when managing API versions, communicating breaking changes, or creating upgrade guides.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

secondsky/claude-skills2312026년 10월 20일 업데이트

Verifies API contracts between services using consumer-driven contracts, schema validation, and tools like Pact. Use when testing microservices communication, preventing breaking changes, or validating OpenAPI specifications.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

secondsky/claude-skills2312026년 10월 20일 업데이트

Master REST and GraphQL API design principles to build intuitive, scalable, and maintainable APIs that delight developers. Use when designing new APIs, reviewing API specifications, or establishing API design standards.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

secondsky/claude-skills2312026년 10월 20일 업데이트

Implements standardized API error responses with proper status codes, logging, and user-friendly messages. Use when building production APIs, implementing error recovery patterns, or integrating error monitoring services.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

secondsky/claude-skills2312026년 10월 20일 업데이트

secondsky의 스킬 모두 보기

이 스킬의 문제 신고