Token导航 LogoToken导航

Agent Skill · 研究检索

drizzle-orm-d1(Drizzle ORM D1 测试)

用于辅助数据库表结构、查询语句、迁移脚本和数据维护任务。它适合让 Agent 分析 schema、编写 SQL、排查查询问题、整理索引或生成迁移建议。使用时需要明确数据库类型、连接环境和目标表,区分只读分析与写入变更;涉及删除、更新、迁移和批量导入时,应优先 dry-run、备份或事务保护,避免误操作。

drizzle-orm-d1 是研究检索类 Agent Skill,可用宿主为 Codex、Claude、Cursor、Gemini CLI,通过GitHub 仓库获取,权限为接触敏感数据;许可证为 MIT,第三方扫描已通过,按安装量在研究检索类的 73,675 个 Skill 里排第 8,696。

总安装 15,814周安装 646GitHub Stars 750下载 5,116核验 2026-05-01

安装说明

本站只整理中文说明,不托管安装包,也不代用户安装。
GitHub
许可证
MIT

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:drizzle-orm-d1(Drizzle ORM D1 测试)
来源仓库:https://github.com/jezweb/claude-skills
仓库路径:skills/drizzle-orm-d1
安装命令:
npx skills add https://github.com/jezweb/claude-skills --skill drizzle-orm-d1
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。不同来源提供的安装方式可能略有差异;本站展示可直接复制的安装命令,安装前请核对来源页面。

skills.shnpx skills
npx skills add https://github.com/jezweb/claude-skills --skill drizzle-orm-d1

这个 Skill 是做什么的

研究检索类 Skill 主要解决「找资料、核对事实、把来源整理清楚」的问题,通常会让助手先检索再总结。

类型安全的 D1 数据库,具有 Drizzle ORM、迁移和适用于 Cloudflare Workers 的批处理 API 模式。

包括架构定义、Drizzle Kit 迁移、关系和 D1 特定的事务批处理 API(D1 不支持 SQL BEGIN) 防止 18 个已记录的错误,包括事务失败、级联数据丢失、100 参数限制、外键问题和嵌套迁移发现 支持动态查询构建、更新插入、日志记录和 Drizzle Studio 进行可视化数据库浏览 关键 D1 规则:使用 db.batch() 对于事务,首先在本地测试迁移,使用整数 使用模式:'时间戳' 对于日期,块批量插入 100 个参数以下

来源仓库内路径:skills/drizzle-orm-d1

上手步骤

4 步
  1. 1

    确认自己的宿主工具

    公开资料标注支持 Codex、Claude、Cursor、Gemini CLI;先确认自己用的是其中之一,再按对应工具的 Skills 目录放置。

  2. 2

    拿到安装命令

    可以直接复制的命令是 npx skills add https://github.com/jezweb/claude-skills --skill drizzle-orm-d1;命令里的占位符换成自己的路径或密钥再执行。

  3. 3

    安装后重启宿主

    命令执行完要完全退出宿主工具再打开,让新装的 Skill 被重新扫描到,否则列表里可能看不到。

  4. 4

    按最小权限试用

    它需要接触敏感数据,先在测试目录或测试账号里跑,确认没问题再放到正式项目。

常见问题

6 条

drizzle-orm-d1 怎么安装?

在终端执行 npx skills add https://github.com/jezweb/claude-skills --skill drizzle-orm-d1。装完完全退出宿主工具再打开,让它重新扫描本地 Skill。

drizzle-orm-d1 支持哪些 AI 工具?

公开资料标注支持 Codex、Claude、Cursor、Gemini CLI。其他工具只要能读取本地 Skill 目录,一般也能手动放进去,但要自己确认触发方式是否一致。

drizzle-orm-d1 需要什么权限?

权限级别是接触敏感数据。该 Skill 可能接触密钥、Token、环境变量或敏感配置,应进入高风险复核队列,默认不自动发布。

drizzle-orm-d1 是免费的吗?

来源标注的许可证是 MIT。本站不代收任何费用,也不托管安装包;能否商用、要不要署名,以许可证原文为准。

drizzle-orm-d1 用的人多吗?

公开数据是累计安装 15,814 次,近一周安装 646 次,下载 5,116 次,GitHub 750 星。这些数字来自第三方目录统计,只能当作热度参考,不代表质量或安全性。

drizzle-orm-d1 安全吗?

第三方扫描结果为通过,但这只覆盖已知的静态检查项,不能替代自己读一遍源码和安装命令。

值得选的地方和要先想清楚的地方

值得选的地方

  • 同时适配 4 种工具,换客户端不用重新找替代品。
  • 3 个目录同时收录,说明这个 Skill 流传比较广。
  • 许可证明确为 MIT,商用和分发边界好判断。
  • 第三方扫描已通过,常见的高风险行为没有命中。

先想清楚的地方

  • 需要接触敏感数据,装到常用环境前要先评估影响面。
  • 第三方目录整理,版本更新和行为细节以来源仓库为准。

适不适合你

更适合

  • 已经在用 Codex,想直接扩展它能力的人。
  • 需要处理研究检索类任务、又不想每次都手写提示词的人。
  • 需要许可证清楚、并且有第三方扫描结果的团队项目。

不太适合

  • 环境里有大量密钥、凭证,不方便给第三方 Skill 读取的人。
  • 需要厂商级技术支持和 SLA 的生产系统。

研究检索类 Skill 对比

6 个同类
Skill总安装GitHub 星权限许可证扫描
find-skills

寻找技能 · Codex、Claude

31,199,81316,486操作浏览器MIT有提醒
self-improving-agent

自我改进 Agent · OpenClaw

16,464,0023,396接触敏感数据MIT-0通过
soultrace

灵魂追踪 · Codex、Claude

7,588,94412需要联网未明确有提醒
self-improving

自我完善 · OpenClaw

6,829,2841,046需要联网MIT-0通过
microsoft-foundry

微软代工厂 · Codex、Claude

6,614,144764调用外部服务未明确有提醒
drizzle-orm-d1

Drizzle ORM D1 测试 · 本页

15,814750接触敏感数据MIT通过

按安装量取同分类前几名;数字来自第三方目录统计,只作热度参考,不代表质量结论。

SKILL.md 原文

Drizzle ORM for Cloudflare D1

Status: Production Ready ✅ Last Updated: 2026-02-03

Commands

CommandPurpose
/db-initSet up Drizzle ORM with D1 (schema, config, migrations)
/migrateGenerate and apply database migrations
/seedSeed database with initial or test data
Latest Version: drizzle-orm@0.45.1, drizzle-kit@0.31.8, better-sqlite3@12.5.0
Dependencies: cloudflare-d1, cloudflare-worker-base

Quick Start (5 Minutes)

# 1. Install
npm install drizzle-orm
npm install -D drizzle-kit

# 2. Configure drizzle.config.ts
import { defineConfig } from 'drizzle-kit';
export default defineConfig({
  schema: './src/db/schema.ts',
  out: './migrations',
  dialect: 'sqlite',
  driver: 'd1-http',
  dbCredentials: {
    accountId: process.env.CLOUDFLARE_ACCOUNT_ID!,
    databaseId: process.env.CLOUDFLARE_DATABASE_ID!,
    token: process.env.CLOUDFLARE_D1_TOKEN!,
  },
});

# 3. Configure wrangler.jsonc
{
  "d1_databases": [{
    "binding": "DB",
    "database_name": "my-database",
    "database_id": "your-database-id",
    "migrations_dir": "./migrations"  // CRITICAL: Points to Drizzle migrations
  }]
}

# 4. Define schema (src/db/schema.ts)
import { sqliteTable, text, integer } from 'drizzle-orm/sqlite-core';
export const users = sqliteTable('users', {
  id: integer('id').primaryKey({ autoIncrement: true }),
  email: text('email').notNull().unique(),
  createdAt: integer('created_at', { mode: 'timestamp' }).$defaultFn(() => new Date()),
});

# 5. Generate & apply migrations
npx drizzle-kit generate
npx wrangler d1 migrations apply my-database --local   # Test first
npx wrangler d1 migrations apply my-database --remote  # Then production

# 6. Query in Worker
import { drizzle } from 'drizzle-orm/d1';
import { users } from './db/schema';
const db = drizzle(env.DB);
const allUsers = await db.select().from(users).all();

D1-Specific Critical Rules

✅ Use db.batch() for transactions - D1 doesn't support SQL BEGIN/COMMIT (see Issue #1) ✅ Test migrations locally first - Always --local before --remote ✅ Use integer with mode: 'timestamp' for dates - D1 has no native date type ✅ Use .$defaultFn() for dynamic defaults - Not .default() for functions ✅ Set migrations_dir in wrangler.jsonc - Points to ./migrations

❌ Never use SQL BEGIN TRANSACTION - D1 requires batch API ❌ Never use drizzle-kit push for production - Use generate + apply ❌ Never mix wrangler.toml and wrangler.jsonc - Use wrangler.jsonc only


Drizzle Kit Tools

Drizzle Studio (Visual Database Browser)

npx drizzle-kit studio
# Opens http://local.drizzle.studio

# For remote D1 database
npx drizzle-kit studio --port 3001

Features:

  • Browse tables and data visually
  • Edit records inline
  • Run custom SQL queries
  • View schema relationships

Migration Commands

CommandPurpose
drizzle-kit generateGenerate SQL migrations from schema changes
drizzle-kit pushPush schema directly (dev only, not for production)
drizzle-kit pullIntrospect existing database → Drizzle schema
drizzle-kit checkValidate migration integrity (race conditions)
drizzle-kit upUpgrade migration snapshots to latest format
# Introspect existing D1 database
npx drizzle-kit pull

# Validate migrations haven't collided
npx drizzle-kit check

Advanced Query Patterns

Dynamic Query Building

Build queries conditionally with .$dynamic():

import { eq, and, or, like, sql } from 'drizzle-orm';

// Base query
function getUsers(filters: { name?: string; email?: string; active?: boolean }) {
  let query = db.select().from(users).$dynamic();

  if (filters.name) {
    query = query.where(like(users.name, `%${filters.name}%`));
  }
  if (filters.email) {
    query = query.where(eq(users.email, filters.email));
  }
  if (filters.active !== undefined) {
    query = query.where(eq(users.active, filters.active));
  }

  return query;
}

// Usage
const results = await getUsers({ name: 'John', active: true });

Upsert (Insert or Update on Conflict)

import { users } from './schema';

// Insert or ignore if exists
await db.insert(users)
  .values({ id: 1, email: 'test@example.com', name: 'Test' })
  .onConflictDoNothing();

// Insert or update specific fields on conflict
await db.insert(users)
  .values({ id: 1, email: 'test@example.com', name: 'Test' })
  .onConflictDoUpdate({
    target: users.email,  // Conflict on unique email
    set: {
      name: sql`excluded.name`,  // Use value from INSERT
      updatedAt: new Date(),
    },
  });

⚠️ D1 Upsert Caveat: Target must be a unique column or primary key.

Debugging with Logging

import { drizzle } from 'drizzle-orm/d1';

// Enable query logging
const db = drizzle(env.DB, { logger: true });

// Custom logger
const db = drizzle(env.DB, {
  logger: {
    logQuery(query, params) {
      console.log('SQL:', query);
      console.log('Params:', params);
    },
  },
});

// Get SQL without executing (for debugging)
const query = db.select().from(users).where(eq(users.id, 1));
const sql = query.toSQL();
console.log(sql.sql, sql.params);

Known Issues Prevention

This skill prevents 18 documented issues:

Issue #1: D1 Transaction Errors

Error: D1_ERROR: Cannot use BEGIN TRANSACTION Source: https://github.com/drizzle-team/drizzle-orm/issues/4212 Why: Drizzle uses SQL BEGIN TRANSACTION, but D1 requires batch API instead. Prevention: Use db.batch([...]) instead of db.transaction()

Issue #2: Foreign Key Constraint Failures

Error: FOREIGN KEY constraint failed: SQLITE_CONSTRAINT Source: https://github.com/drizzle-team/drizzle-orm/issues/4089 Why: Drizzle uses PRAGMA foreign_keys = OFF; which causes migration failures. Prevention: Define foreign keys with cascading: .references(() => users.id, {onDelete: 'cascade'})

Issue #3: Module Import Errors in Production

Error: Error: No such module "wrangler" Source: https://github.com/drizzle-team/drizzle-orm/issues/4257 Why: Importing from wrangler package in runtime code fails in production. Prevention: Use import {drizzle} from 'drizzle-orm/d1', never import from wrangler

Issue #4: D1 Binding Not Found

Error: TypeError: Cannot read property 'prepare' of undefined Why: Binding name in code doesn't match wrangler.jsonc configuration. Prevention: Ensure "binding": "DB" in wrangler.jsonc matches env.DB in code

Issue #5: Migration Apply Failures

Error: Migration failed to apply: near "...": syntax error Why: Syntax errors or applying migrations out of order. Prevention: Test locally first (--local), review generated SQL, regenerate if needed

Issue #6: Schema TypeScript Inference Errors

Error: Type instantiation is excessively deep and possibly infinite Why: Complex circular references in relations. Prevention: Use explicit types with InferSelectModel<typeof users>

Issue #7: Prepared Statement Caching Issues

Error: Stale or incorrect query results Why: D1 doesn't cache prepared statements like traditional SQLite. Prevention: Always use .all() or .get() methods, don't reuse statements across requests

Issue #8: Transaction Rollback Patterns

Error: Transaction doesn't roll back on error Why: D1 batch API doesn't support traditional rollback. Prevention: Implement error handling with manual cleanup in try/catch

Issue #9: TypeScript Strict Mode Errors

Error: Type errors with strict: true Why: Drizzle types can be loose. Prevention: Use explicit return types: Promise<User | undefined>

Issue #10: Drizzle Config Not Found

Error: Cannot find drizzle.config.ts Why: Wrong file location or name. Prevention: File must be drizzle.config.ts in project root

Issue #11: Remote vs Local D1 Confusion

Error: Changes not appearing in dev or production Why: Applying migrations to wrong database. Prevention: Use --local for dev, --remote for production

Issue #12: wrangler.toml vs wrangler.jsonc

Error: Configuration not recognized Why: Mixing TOML and JSON formats. Prevention: Use wrangler.jsonc consistently (supports comments)

Issue #13: D1 100-Parameter Limit in Bulk Inserts

Error: too many SQL variables at offset Source: drizzle-orm#2479, Cloudflare D1 Limits Why It Happens: Cloudflare D1 has a hard limit of 100 bound parameters per query. When inserting multiple rows, Drizzle doesn't automatically chunk. If (rows × columns) > 100, the query fails. Prevention: Use manual chunking or autochunk pattern

Example - When It Fails:

// 35 rows × 3 columns = 105 parameters → FAILS
const books = Array(35).fill({}).map((_, i) => ({
  id: i.toString(),
  title: "Book",
  author: "Author",
}));

await db.insert(schema.books).values(books);
// Error: too many SQL variables at offset

Solution - Manual Chunking:

async function batchInsert<T>(
  db: any,
  table: any,
  items: T[],
  chunkSize = 32
) {
  for (let i = 0; i < items.length; i += chunkSize) {
    await db.insert(table).values(items.slice(i, i + chunkSize));
  }
}

await batchInsert(db, schema.books, books);

Solution - Auto-Chunk by Column Count:

const D1_MAX_PARAMETERS = 100;

async function autochunk<T extends Record<string, unknown>, U>(
  { items, otherParametersCount = 0 }: {
    items: T[];
    otherParametersCount?: number;
  },
  cb: (chunk: T[]) => Promise<U>,
) {
  const chunks: T[][] = [];
  let chunk: T[] = [];
  let chunkParameters = 0;

  for (const item of items) {
    const itemParameters = Object.keys(item).length;

    if (chunkParameters + itemParameters + otherParametersCount > D1_MAX_PARAMETERS) {
      chunks.push(chunk);
      chunkParameters = itemParameters;
      chunk = [item];
      continue;
    }

    chunk.push(item);
    chunkParameters += itemParameters;
  }

  if (chunk.length) chunks.push(chunk);

  const results: U[] = [];
  for (const c of chunks) {
    results.push(await cb(c));
  }

  return results.flat();
}

// Usage
const inserted = await autochunk(
  { items: books },
  (chunk) => db.insert(schema.books).values(chunk).returning()
);

Note: This also affects drizzle-seed. Use seed(db, schema, {count: 10}) to limit seed size.

Issue #14: findFirst with Batch API Returns Error Instead of Undefined

Error: TypeError: Cannot read properties of undefined (reading '0') Source: drizzle-orm#2721 Why It Happens: When using findFirst in a batch operation with D1, if no results are found, Drizzle throws a TypeError instead of returning null or undefined. This breaks error handling patterns that expect falsy return values. Prevention: Use pnpm patch to fix the D1 session handler, or avoid findFirst in batch operations

Example - When It Fails:

// Works fine - returns null/undefined when not found
const result = await db.query.table.findFirst({
  where: eq(schema.table.key, 'not-existing'),
});

// Throws TypeError instead of returning undefined
const [result] = await db.batch([
  db.query.table.findFirst({
    where: eq(schema.table.key, 'not-existing'),
  }),
]);
// Error: TypeError: Cannot read properties of undefined (reading '0')

Solution - Patch drizzle-orm:

# Create patch with pnpm
pnpm patch drizzle-orm

Then edit node_modules/drizzle-orm/d1/session.js:

// In mapGetResult method, add null check:
if (!result) {
  return undefined;
}
if (this.customResultMapper) {
  return this.customResultMapper([result]);
}

Workaround - Avoid findFirst in Batch:

// Instead of batch with findFirst, use separate queries
const result = await db.query.table.findFirst({
  where: eq(schema.table.key, key),
});

Issue #15: D1 Generated Columns Not Supported

Error: No schema API for generated columns Source: drizzle-orm#4538, D1 Generated Columns Why It Happens: Cloudflare D1 supports generated columns for extracting/calculating values from JSON or other columns, which can dramatically improve query performance when indexed. Drizzle ORM doesn't have a schema API to define these columns, forcing users to write raw SQL. Prevention: Use raw SQL migrations for generated columns

Example - D1 Supports This:

-- D1 supports this, but Drizzle has no JS equivalent
CREATE TABLE products (
  id INTEGER PRIMARY KEY,
  data TEXT,
  price REAL GENERATED ALWAYS AS (json_extract(data, '$.price')) STORED
);
CREATE INDEX idx_price ON products(price);

Workaround - Use Raw SQL:

import { sql } from 'drizzle-orm';

// Current workaround - raw SQL only
await db.run(sql`
  CREATE TABLE products (
    id INTEGER PRIMARY KEY,
    data TEXT,
    price REAL GENERATED ALWAYS AS (json_extract(data, '$.price')) STORED
  )
`);

// Or in migration file (migrations/XXXX_add_generated.sql)
CREATE INDEX idx_price ON products(price);

Note: This is a known limitation, not a bug. Feature requested but not yet implemented.

Issue #16: Migration Generator Silently Causes CASCADE DELETE Data Loss

Error: Related data silently deleted during migrations Source: drizzle-orm#4938 Why It Happens: Drizzle generates PRAGMA foreign_keys=OFF before table recreation, but Cloudflare D1 ignores this pragma. CASCADE DELETE still triggers, destroying all related data. Prevention: Manually rewrite dangerous migrations with backup/restore pattern

⚠️ CRITICAL WARNING: This can cause permanent data loss in production.

When It Happens: Any schema change that requires table recreation (adding/removing columns, changing types) will DROP and recreate the table. If foreign keys reference this table with onDelete: "cascade", ALL related data is deleted.

Example - Dangerous Migration:

// Schema with cascade relationships
export const account = sqliteTable("account", {
  accountId: integer("account_id").primaryKey(),
  name: text("name"),
});

export const property = sqliteTable("property", {
  propertyId: integer("property_id").primaryKey(),
  accountId: integer("account_id").references(() => account.accountId, {
    onDelete: "cascade"  // ⚠️ CASCADE DELETE
  }),
});

// Change account schema (e.g., add a column)
// npx drizzle-kit generate creates:
// DROP TABLE account;  -- ⚠️ Silently destroys ALL properties via cascade!
// CREATE TABLE account (...);

Safe Migration Pattern:

-- Manually rewrite migration to backup related data
PRAGMA foreign_keys=OFF;  -- D1 ignores this, but include anyway

-- 1. Backup related tables
CREATE TABLE backup_property AS SELECT * FROM property;

-- 2. Drop and recreate parent table
DROP TABLE account;
CREATE TABLE account (
  account_id INTEGER PRIMARY KEY,
  name TEXT,
  -- new columns here
);

-- 3. Restore related data
INSERT INTO property SELECT * FROM backup_property;
DROP TABLE backup_property;

PRAGMA foreign_keys=ON;

Detection: Always review generated migrations before applying. Look for:

  • DROP TABLE statements for tables with foreign key references
  • Tables with onDelete: "cascade" relationships

Workarounds:

  1. Option 1: Manually rewrite migrations (safest)
  2. Option 2: Use onDelete: "set null" instead of "cascade" for schema changes
  3. Option 3: Temporarily remove foreign keys during migration

Reproduction: https://github.com/ZerGo0/drizzle-d1-reprod

Impact: Affects better-auth migration from v1.3.7+, any D1 schema with foreign keys.

Issue #17: sql Template in D1 Batch Causes TypeError

Error: TypeError: Cannot read properties of undefined (reading 'bind') Source: drizzle-orm#2277 Why It Happens: Using sql template literals inside db.batch() causes TypeError. The same SQL works fine outside of batch operations. Prevention: Use query builder instead of sql template in batch operations

Example - When It Fails:

const upsertSql = sql`insert into ${schema.subscriptions}
  (id, status) values (${id}, ${status})
  on conflict (id) do update set status = ${status}
  returning *`;

// Works fine
const [subscription] = await db.all<Subscription>(upsertSql);

// Throws TypeError: Cannot read properties of undefined (reading 'bind')
const [[batchSubscription]] = await db.batch([
  db.all<Subscription>(upsertSql),
]);

Solution - Use Query Builder:

// Use Drizzle query builder instead
const [result] = await db.batch([
  db.insert(schema.subscriptions)
    .values({ id, status })
    .onConflictDoUpdate({
      target: schema.subscriptions.id,
      set: { status }
    })
    .returning()
]);

Workaround - Convert to Native D1:

import { SQLiteSyncDialect } from 'drizzle-orm/sqlite-core';

const sqliteDialect = new SQLiteSyncDialect();
const upsertQuery = sqliteDialect.sqlToQuery(upsertSql);
const [result] = await D1.batch([
  D1.prepare(upsertQuery.sql).bind(...upsertQuery.params),
]);

Issue #18: Drizzle 1.0 Nested Migrations Not Found by Wrangler

Error: Migrations silently fail to apply (no error message) Source: drizzle-orm#5266 Why It Happens: Drizzle 1.0 beta generates nested migration folders, but wrangler d1 migrations apply only looks for files directly in the configured directory. Prevention: Flatten migrations with post-generation script

Migration Structure Issue:

# Drizzle 1.0 beta generates this:
migrations/
  20260116123456_random/
    migration.sql
  20260117234567_another/
    migration.sql

# But wrangler expects this:
migrations/
  20260116123456_random.sql
  20260117234567_another.sql

Detection:

npx wrangler d1 migrations apply my-db --remote
# Output: "No migrations found" (even though migrations exist)

Solution - Post-Generation Script:

// scripts/flatten-migrations.ts
import fs from 'fs/promises';
import path from 'path';

const migrationsDir = './migrations';

async function flattenMigrations() {
  const entries = await fs.readdir(migrationsDir, { withFileTypes: true });

  for (const entry of entries) {
    if (entry.isDirectory()) {
      const sqlFile = path.join(migrationsDir, entry.name, 'migration.sql');
      const flatFile = path.join(migrationsDir, `${entry.name}.sql`);

      // Move migration.sql out of folder
      await fs.rename(sqlFile, flatFile);

      // Remove empty folder
      await fs.rmdir(path.join(migrationsDir, entry.name));

      console.log(`Flattened: ${entry.name}/migration.sql → ${entry.name}.sql`);
    }
  }
}

flattenMigrations().catch(console.error);

package.json Integration:

{
  "scripts": {
    "db:generate": "drizzle-kit generate",
    "db:flatten": "tsx scripts/flatten-migrations.ts",
    "db:migrate": "npm run db:generate && npm run db:flatten && wrangler d1 migrations apply my-db"
  }
}

Workaround Until Fixed: Always run the flatten script after generating migrations:

npx drizzle-kit generate
tsx scripts/flatten-migrations.ts
npx wrangler d1 migrations apply my-db --remote

Status: Feature request to add flat: true config option (not yet implemented).


Batch API Pattern (D1 Transactions)

// ❌ DON'T: Use traditional transactions (fails with D1_ERROR)
await db.transaction(async (tx) => { /* ... */ });

// ✅ DO: Use D1 batch API
const results = await db.batch([
  db.insert(users).values({ email: 'test@example.com', name: 'Test' }),
  db.insert(posts).values({ title: 'Post', content: 'Content', authorId: 1 }),
]);

// With error handling
try {
  await db.batch([...]);
} catch (error) {
  console.error('Batch failed:', error);
  // Manual cleanup if needed
}

Using Bundled Resources

Scripts (scripts/)

check-versions.sh - Verify package versions are up to date

./scripts/check-versions.sh

Output:

Checking Drizzle ORM versions...
✓ drizzle-orm: 0.44.7 (latest)
✓ drizzle-kit: 0.31.5 (latest)

References (references/)

Claude should load these when you need specific deep-dive information:

  • wrangler-setup.md - Complete Wrangler configuration guide (local vs remote, env vars)
  • schema-patterns.md - All D1/SQLite column types, constraints, indexes
  • migration-workflow.md - Complete migration workflow (generate, test, apply)
  • query-builder-api.md - Full Drizzle query builder API reference
  • common-errors.md - All 18 errors with detailed solutions
  • links-to-official-docs.md - Organized links to official documentation

When to load:

  • User asks about specific column types → load schema-patterns.md
  • User encounters migration errors → load migration-workflow.md + common-errors.md
  • User needs complete API reference → load query-builder-api.md

Dependencies

Required:

  • drizzle-orm@0.45.1 - ORM runtime
  • drizzle-kit@0.31.8 - CLI tool for migrations

Optional:

  • better-sqlite3@12.4.6 - For local SQLite development
  • @cloudflare/workers-types@4.20251125.0 - TypeScript types

Skills:

  • cloudflare-d1 - D1 database creation and raw SQL queries
  • cloudflare-worker-base - Worker project structure and Hono setup

Official Documentation


Package Versions (Verified 2026-01-06)

{
  "dependencies": {
    "drizzle-orm": "^0.45.1"
  },
  "devDependencies": {
    "drizzle-kit": "^0.31.8",
    "@cloudflare/workers-types": "^4.20260103.0",
    "better-sqlite3": "^12.5.0"
  }
}

Production Example

This skill is based on production patterns from:

  • Cloudflare Workers + D1: Serverless edge databases
  • Drizzle ORM: Type-safe ORM used in production apps
  • Errors: 0 (all 18 known issues prevented)
  • Validation: ✅ Complete blog example (users, posts, comments)

Last verified: 2026-01-20 | Skill version: 3.1.0 | Changes: Added 6 critical findings (100-parameter limit, cascade data loss, nested migrations, batch API edge cases, generated columns limitation)

Token Savings: ~60% compared to manual setup Error Prevention: 100% (all 18 known issues documented and prevented) Ready for production! ✅

平台分布

Claude Code

25.86%
按下载量换算1,323

Cursor

24.02%
按下载量换算1,229

Antigravity

15.69%
按下载量换算803

Gemini CLI

12.12%
按下载量换算620

OpenCode

7.74%
按下载量换算396

Codex

3.62%
按下载量换算185

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

接触敏感数据

该 Skill 可能接触密钥、Token、环境变量或敏感配置,应进入高风险复核队列,默认不自动发布。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。

继续浏览同类 Skills