← ClaudeAtlas

cloudflare-bindingslisted

This skill activates when working with Cloudflare Workers bindings like D1, KV, R2, Durable Objects, or environment variables. It provides patterns for database access, caching, file storage, and secrets management.
smicolon/ai-kit · ★ 3 · AI & Automation · score 64
Install: claude install-skill smicolon/ai-kit
# Cloudflare Bindings Patterns for Cloudflare Workers bindings in Hono. ## Type Definitions Define all bindings in a central type: ```typescript // types/bindings.ts export type Env = { Bindings: { // D1 Database DB: D1Database // KV Namespace KV: KVNamespace // R2 Bucket BUCKET: R2Bucket // Durable Object COUNTER: DurableObjectNamespace // Environment Variables ENVIRONMENT: 'development' | 'staging' | 'production' API_KEY: string JWT_SECRET: string } Variables: { user: User requestId: string } } ``` ## D1 Database ### Basic Queries ```typescript app.get('/users', async (c) => { const db = c.env.DB // Select all const { results } = await db .prepare('SELECT * FROM users WHERE deleted_at IS NULL') .all() return c.json({ data: results }) }) app.get('/users/:id', async (c) => { const db = c.env.DB const id = c.req.param('id') // Select one const user = await db .prepare('SELECT * FROM users WHERE id = ?') .bind(id) .first() if (!user) { return c.json({ error: 'User not found' }, 404) } return c.json({ data: user }) }) ``` ### Insert and Update ```typescript app.post('/users', async (c) => { const db = c.env.DB const { email, name } = c.req.valid('json') const id = crypto.randomUUID() const result = await db .prepare('INSERT INTO users (id, email, name) VALUES (?, ?, ?)') .bind(id, email, name) .run() return c.json({ data: { id,