secondsky/claude-skills / plugins/cloudflare-hyperdrive/skills/cloudflare-hyperdrive
cloudflare-hyperdrive
VerifiedCloudflare Hyperdrive for Workers-to-database connections with pooling and caching. Use for PostgreSQL/MySQL, Drizzle/Prisma, or encountering pool errors, TLS issues, connection refused.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 7.2 KB |
| references/connection-pooling.md | markdown | 11.5 KB |
| references/drizzle-integration.md | markdown | 12.2 KB |
| references/prisma-integration.md | markdown | 12.8 KB |
| references/query-caching.md | markdown | 12.2 KB |
| references/setup-guide.md | markdown | 2.6 KB |
| references/supported-databases.md | markdown | 11.1 KB |
| references/tls-ssl-setup.md | markdown | 10.5 KB |
| references/troubleshooting.md | markdown | 13.3 KB |
| references/wrangler-commands.md | markdown | 10.6 KB |
| scripts/check-versions.shexecutable | script | 3.4 KB |
| templates/drizzle-mysql.ts | script | 2.2 KB |
| templates/drizzle-postgres.ts | script | 2.1 KB |
| templates/local-dev-setup.shexecutable | script | 2.4 KB |
| templates/mysql2-basic.ts | script | 2.0 KB |
| templates/postgres-basic.ts | script | 1.7 KB |
| templates/postgres-js.ts | script | 2.6 KB |
| templates/postgres-pool.ts | script | 2.4 KB |
| templates/prisma-postgres.ts | script | 3.3 KB |
| templates/wrangler-hyperdrive-config.jsonc | other | 1.0 KB |
templates/prisma-postgres.ts
View on GitHub/**
* Prisma ORM with PostgreSQL
*
* Type-safe ORM for PostgreSQL via Hyperdrive using driver adapters.
*
* Install: npm install prisma @prisma/client pg @prisma/adapter-pg
*
* Setup:
* 1. npx prisma init
* 2. Define schema in prisma/schema.prisma
* 3. npx prisma generate --no-engine
* 4. npx prisma migrate dev (for migrations)
*
* CRITICAL: Must use driver adapters (@prisma/adapter-pg) for Hyperdrive
*/
import { PrismaPg } from "@prisma/adapter-pg";
import { PrismaClient } from "@prisma/client";
import { Pool } from "pg";
type Bindings = {
HYPERDRIVE: Hyperdrive;
};
/**
* Example Prisma schema (prisma/schema.prisma):
*
* generator client {
* provider = "prisma-client-js"
* previewFeatures = ["driverAdapters"]
* }
*
* datasource db {
* provider = "postgresql"
* url = env("DATABASE_URL")
* }
*
* model User {
* id Int @id @default(autoincrement())
* name String
* email String @unique
* createdAt DateTime @default(now())
* posts Post[]
* }
*
* model Post {
* id Int @id @default(autoincrement())
* title String
* content String?
* published Boolean @default(false)
* authorId Int
* author User @relation(fields: [authorId], references: [id])
* }
*/
export default {
async fetch(
request: Request,
env: Bindings,
ctx: ExecutionContext
): Promise<Response> {
// Create pg.Pool for driver adapter
const pool = new Pool({
connectionString: env.HYPERDRIVE.connectionString,
max: 5
});
// Create Prisma driver adapter
const adapter = new PrismaPg(pool);
// Create Prisma client with adapter
const prisma = new PrismaClient({ adapter });
try {
// Example: Create user
const newUser = await prisma.user.create({
data: {
name: "John Doe",
email: `john.${Date.now()}@example.com`
}
});
// Example: Find all users
const allUsers = await prisma.user.findMany({
include: {
posts: true // Include related posts
}
});
// Example: Find user by email
const user = await prisma.user.findUnique({
where: {
email: "john@example.com"
}
});
// Example: Update user
await prisma.user.update({
where: { id: newUser.id },
data: { name: "Jane Doe" }
});
// Example: Create post with relation
await prisma.post.create({
data: {
title: "My First Post",
content: "Hello World!",
published: true,
authorId: newUser.id
}
});
// Example: Complex query with filters
const recentUsers = await prisma.user.findMany({
where: {
createdAt: {
gte: new Date('2024-01-01')
}
},
orderBy: {
createdAt: 'desc'
},
take: 10
});
return Response.json({
success: true,
data: {
newUser,
allUsers,
user,
recentUsers
}
});
} catch (error: any) {
console.error("Database error:", error);
return Response.json({
success: false,
error: error.message
}, {
status: 500
});
} finally {
// Clean up connections
ctx.waitUntil(pool.end());
}
}
};
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| deprecation-and-migrationaddyosmani/agent-skillsManages deprecation and migration. Use when removing old systems, APIs, or features. Use when migrating users from one implementation to another. Use when migrating a database schema in production, such as renaming or dropping a column without downtime (expand/contract). Use when deciding whether to maintain or sunset existing code. | Stars: 119k | Updated | Claude CodeCodex | Verified | Install |
| performance-optimizationaddyosmani/agent-skillsOptimizes application performance across frontend, backend, queries, and databases. Use when performance requirements exist, when you suspect performance regressions, when Core Web Vitals or load times need improvement, when N+1 query patterns need fixing, or when profiling reveals bottlenecks. | Stars: 119k | Updated | Claude CodeCodex | Verified | Install |
| Agent Cost Reportthedotmack/claude-memBelievable agent cost report for any period, default the last 7 full days PT, not counting today. Measured tokens from Claude Code transcripts priced at OpenRouter list prices (ESTIMATED), measured provider spend when a sanctioned source exists, note-taker cost separate, Timing-style HTML/PDF plus report.json, line-items.csv, evidence.json. | Stars: 118k | Updated | Claude CodeCodex | Verified | Install |
| Agent Cost Reportthedotmack/claude-memBelievable agent cost report for any period, default the last 7 full days PT, not counting today. Measured tokens from Claude Code transcripts priced at OpenRouter list prices (ESTIMATED), measured provider spend when a sanctioned source exists, note-taker cost separate, Timing-style HTML/PDF plus report.json, line-items.csv, evidence.json. | Stars: 118k | Updated | Claude CodeCodex | Verified | Install |