Agent skill

Drizzle Orm D1

by secondsky in secondsky/claude-skills

| Type-safe ORM for Cloudflare D1 databases using Drizzle. An agent skill from secondsky/claude-skills.

MITAuto-check passedDatabases

Install Drizzle Orm D1

skills CLI
$ npx skills add secondsky/claude-skills --skill drizzle-orm-d1 -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install secondsky/claude-skills drizzle-orm-d1 --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/secondsky/claude-skills.git skills-src && mkdir -p .claude/skills && cp -r skills-src/plugins/drizzle-orm-d1/skills/drizzle-orm-d1 .claude/skills/drizzle-orm-d1 && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
drizzle-orm-d1
GitHub stars
227
Token cost
~2.4k tokens
SKILL.md length
566 words
Files
20 (incl. scripts, references)
Skills in repo
169
Repo updated
First seen
Licence
MIT

At a glance

| Type-safe ORM for Cloudflare D1 databases using Drizzle. An agent skill from secondsky/claude-skills.

  • Works in 5 steps: Install Drizzle → Configure Drizzle Kit → Define Schema → …
  • : building D1 database schemas
  • SKILL.md covers Quick Start (10 Minutes), Critical Rules, Top 5 Critical Errors and Common Patterns Summary, plus 8 more sections
  • Runs TypeScript and Shell scripts from its folder; calls npm, bunx and bun; needs CLOUDFLARE_D1_TOKEN

What it does

Drizzle Orm D1 is an agent skill from secondsky/claude-skills. | Type-safe ORM for Cloudflare D1 databases using Drizzle. Use when: building D1 database schemas, writing type-safe SQL queries, managing migrations with Drizzle Kit, defining table relations, implementing prepared statements, using D1 batch API, or encountering D1ERROR, transaction errors, foreign key constraint failures, or schema inference issues.

Its SKILL.md is about 2.4k tokens, which your agent loads only when the skill is triggered. The skill folder holds 23 other files, including scripts and reference files (for example `references/common-errors.md`, `references/error-catalog.md` and `references/links-to-official-docs.md`).

It sits in Databases, covering ORMs and data access, Type safety and SQL. It works with Drizzle ORM, Cloudflare, SQL and Cloudflare Workers. The repository describes itself as: Production-ready skills for Claude Code CLI - Cloudflare, React, Tailwind v4, and AI integrations. The licence is MIT.

When your agent uses it

  • : building D1 database schemas
  • Writing type-safe SQL queries
  • Managing migrations with Drizzle Kit
  • Defining table relations

Example prompts

  • “/drizzle-orm-d1”

Requirements

  • Node.js
  • A Bash shell
  • A credential in CLOUDFLARE_D1_TOKEN

Workflow steps

5 steps, taken from the step headings in SKILL.md.

  1. Install Drizzle
  2. Configure Drizzle Kit
  3. Define Schema
  4. Generate & Apply Migrations
  5. Query in Worker

What it can do on your machine

Read from SKILL.md and the folder at commit 8837836. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Ships 1 file in scripts/ (TypeScript and Shell, from the files we listed), which the agent can run.

    Shell commands in SKILL.md call:

    • npm
    • bunx
    • bun
    • wrangler

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    Links to these hosts (documentation or services it may open):

    • orm.drizzle.team
    • github.com

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names these keys or tokens, usually read from environment variables:

    • CLOUDFLARE_D1_TOKEN

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Drizzle Orm D1 loads about 2.4k tokens when it runs, and up to ~9.4k if it reads all its reference files. Until then it costs about 92 tokens; SKILL.md has 566 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~92
When it runs · the whole SKILL.md, loaded when a task matches
~2.4k
With references · SKILL.md plus every file in references/, read only if the agent opens them
~9.4k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); the scripts in this folder are not scanned.

SKILL.md

The full file from secondsky/claude-skills at commit 8837836, republished under its MIT licence (© secondsky). 566 words, ~2,357 tokens.

Download SKILL.mdSave it as .claude/skills/drizzle-orm-d1/SKILL.md (or your agent's skills folder). This skill also uses 19 other files; get the full folder from GitHub.
name
drizzle-orm-d1
description
| Type-safe ORM for Cloudflare D1 databases using Drizzle. Use when: building D1 database schemas, writing type-safe SQL queries, managing migrations with Drizzle Kit, defining table relations, implementing prepared statements, using D1 batch API, or encountering D1_ERROR, transaction errors, foreign key constraint failures, or schema inference issues.
metadata.keywords
drizzle orm, drizzle d1, type-safe sql, drizzle schema, drizzle migrations, drizzle kit, orm cloudflare, d1 orm, drizzle typescript, drizzle relations…
license
MIT

Drizzle ORM for Cloudflare D1

Status: Production Ready ✅ Last Updated: 2025-12-14 Latest Version: drizzle-orm@0.45.2, drizzle-kit@0.31.10 Dependencies: cloudflare-d1, cloudflare-worker-base


Quick Start (10 Minutes)

1. Install Drizzle
bash
bun add drizzle-orm drizzle-kit
2. Configure Drizzle Kit

Create drizzle.config.ts:

typescript
import { defineConfig } from 'drizzle-kit';

export default defineConfig({
  schema: './src/db/schema.ts',
  out: './migrations',
  dialect: 'sqlite',          // MANDATORY since drizzle-kit 0.21 (D1 = sqlite)
  driver: 'd1-http',          // D1 HTTP driver for remote migrations/Studio
  dbCredentials: {            // MANDATORY: drizzle-kit 0.30+ tightened zod validation
    accountId: process.env.CLOUDFLARE_ACCOUNT_ID!,
    databaseId: process.env.CLOUDFLARE_DATABASE_ID!,
    token: process.env.CLOUDFLARE_D1_TOKEN!,
  },
});

drizzle-kit 0.30/0.31 note: dialect and dbCredentials are now strictly validated. A config that omits dialect or uses the old connectionString/ uri keys will fail validation. For D1 use dialect: 'sqlite' + driver: 'd1-http' with accountId/databaseId/token (or wrangler-based credentials). The runtime migrate() signature in drizzle-orm/<driver>/migrator is unchanged from 0.36 → 0.45 (it changes only in 1.0-beta, which is out of scope for ^0.45).

3. Define Schema

Create src/db/schema.ts:

typescript
import { sqliteTable, text, integer } from 'drizzle-orm/sqlite-core';
import { relations } from 'drizzle-orm';

export const users = sqliteTable('users', {
  id: integer('id').primaryKey({ autoIncrement: true }),
  email: text('email').notNull().unique(),
  name: text('name').notNull(),
  createdAt: integer('created_at', { mode: 'timestamp' }).$defaultFn(() => new Date()),
});

export const posts = sqliteTable('posts', {
  id: integer('id').primaryKey({ autoIncrement: true }),
  title: text('title').notNull(),
  content: text('content').notNull(),
  authorId: integer('author_id')
    .notNull()
    .references(() => users.id, { onDelete: 'cascade' }),
});

export const usersRelations = relations(users, ({ many }) => ({
  posts: many(posts),
}));
4. Generate & Apply Migrations
bash
bunx drizzle-kit generate                           # Generate SQL
bunx wrangler d1 migrations apply my-database --local   # Apply local
bunx wrangler d1 migrations apply my-database --remote  # Apply prod
5. Query in Worker
typescript
import { drizzle } from 'drizzle-orm/d1';
import { users } from './db/schema';
import { eq } from 'drizzle-orm';

export default {
  async fetch(request: Request, env: { DB: D1Database }): Promise<Response> {
    const db = drizzle(env.DB);
    const allUsers = await db.select().from(users).all();
    return Response.json(allUsers);
  },
};

Critical Rules

Always Do
RuleWhy
Use drizzle-kit generate for migrationsNever write SQL manually
Test migrations locally first--local before --remote
Use .get() for single resultsReturns first row or undefined
Use db.batch() for transactionsD1 doesn't support SQL BEGIN/COMMIT
Use integer with mode: 'timestamp' for datesD1 has no native date type
Use .$defaultFn() for dynamic defaultsNot .default() for functions
Never Do
RuleWhy
Use SQL BEGIN TRANSACTIOND1 requires batch API (Error #1)
Mix drizzle-kit migrate and wrangler applyUse Wrangler only
Use drizzle-kit push for productionUse generate + apply
Commit credentials in drizzle.config.tsUse env vars
Use .default() for function callsUse .$defaultFn() instead

Top 5 Critical Errors

#ErrorSolution
1D1_ERROR: Cannot use BEGIN TRANSACTIONUse db.batch([...]) instead of db.transaction()
2FOREIGN KEY constraint failedDefine cascading: .references(() => users.id, { onDelete: 'cascade' })
3env.DB is undefinedEnsure binding in wrangler.jsonc matches env.DB
4No such module "wrangler"Use import { drizzle } from 'drizzle-orm/d1'
5Type instantiation excessively deepUse InferSelectModel<typeof users> for explicit types

See: references/error-catalog.md for all 12 errors with complete solutions.


Common Patterns Summary

PatternUse CaseTemplate
CRUD OperationsBasic database operationstemplates/basic-queries.ts
Relations & JoinsNested queries, manual joinstemplates/relations-queries.ts
Batch OperationsTransactions (D1 batch API)templates/transactions.ts
Schema DesignNaming, indexes, soft deletesreferences/schema-patterns.md

Configuration Summary

FilePurposeTemplate
drizzle.config.tsDrizzle Kit configurationtemplates/drizzle.config.ts
wrangler.jsoncD1 binding setupreferences/wrangler-setup.md
package.jsonnpm scripts for migrationstemplates/package.json

npm scripts:

json
{
  "db:generate": "drizzle-kit generate",
  "db:migrate:local": "wrangler d1 migrations apply my-database --local",
  "db:migrate:remote": "wrangler d1 migrations apply my-database --remote"
}

Show full SKILL.md (228 more words)Show less

Migration Workflow

StepCommandNotes
1. Edit schemaEdit src/db/schema.tsMake changes
2. Generatenpm run db:generateCreates SQL migration
3. Test localnpm run db:migrate:localVerify locally
4. Deploy codenpm run deployPush to Cloudflare
5. Apply prodnpm run db:migrate:remoteApply migration

See: references/migration-workflow.md for complete workflow.


TypeScript Type Inference

typescript
import { InferSelectModel, InferInsertModel } from 'drizzle-orm';
import { users } from './db/schema';

export type User = InferSelectModel<typeof users>;
export type NewUser = InferInsertModel<typeof users>;

When to Load References

ReferenceLoad When...
references/error-catalog.mdDebugging D1 errors, transaction failures, binding issues
references/schema-patterns.mdDesigning schemas, naming conventions, indexes, soft deletes
references/migration-workflow.mdSetting up or troubleshooting migrations
references/query-builder-api.mdComplex queries, operators, joins syntax
references/wrangler-setup.mdConfiguring wrangler.jsonc for D1
references/common-errors.mdQuick error lookup

Bundled Resources

Templates: basic-schema.ts, basic-queries.ts, transactions.ts, relations-queries.ts, prepared-statements.ts, drizzle.config.ts, package.json

References: error-catalog.md, schema-patterns.md, migration-workflow.md, query-builder-api.md, wrangler-setup.md, common-errors.md, links-to-official-docs.md


Dependencies

json
{
  "dependencies": {
    "drizzle-orm": "^0.45.2"
  },
  "devDependencies": {
    "drizzle-kit": "^0.31.10"
  }
}

Secure Installation

When installing Drizzle ORM and D1 driver packages, follow supply chain security best practices:

  • Block post-install scripts — npm config set ignore-scripts true (or Bun: disabled by default)
  • Cooldown period — Wait 7 days for new package versions to be vetted by the community
  • Audit before installing — Run socket package score npm <pkg> or use socket npm install <pkg> to check packages

Load the dependency-upgrade skill for full security configuration including Socket CLI integration, cooldown setup, lockfile validation, and CI enforcement.

Official Documentation


Token Savings: ~65% (comprehensive patterns in references) Error Prevention: 100% (all 12 documented issues) Ready for production! ✅

© secondsky, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 19 other files (scripts, references) in plugins/drizzle-orm-d1/skills/drizzle-orm-d1 of secondsky/claude-skills.

  • SKILL.md
  • references/common-errors.md
  • references/error-catalog.md
  • references/links-to-official-docs.md
  • references/migration-workflow.md
  • references/query-builder-api.md
  • references/schema-patterns.md
  • references/wrangler-setup.md
  • scripts/check-versions.sh
  • templates/basic-queries.ts
  • templates/basic-schema.ts
  • templates/client.ts
  • templates/cloudflare-worker-integration.ts
  • templates/drizzle.config.ts
  • templates/migrations/0001_example.sql
  • templates/package.json
  • templates/prepared-statements.ts
  • … and 3 more

Open the folder on GitHubat commit 8837836

Compare with similar skills

Drizzle Orm D1 next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Drizzle Orm D1 compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Drizzle Orm D1 this skillsecondsky/claude-skills227—~2.4kAutomated safety check: PassMIT
Drizzle Ormgrowupanand/ConvoForm1011 repos~2.7kAutomated safety check: PassApache-2.0
Drizzle Orm Expertdavila7/claude-code-templates32k3 repos~2.6kAutomated safety check: PassMIT
Cloudflare D1alinaqi/maggy707—~4.1kAutomated safety check: PassMIT
Database FundamentalsDanielPodolsky/ownyourcode2901 repos~1.6kAutomated safety check: PassMIT
Basincloudflare/skills3k1 repos~684Automated safety check: PassApache-2.0

Similar skills

  • Drizzle Orm

    growupanand/ConvoForm

    Type-safe SQL ORM for TypeScript with zero runtime overhead. An agent skill from growupanand/ConvoForm.

    101 GitHub starsUsed in 1 repo~2.7k tokens
    DatabasesAuto-check passed
  • Drizzle Orm Expert

    davila7/claude-code-templates

    Expert in Drizzle ORM for TypeScript — schema design, relational queries, migrations, and serverless database integration.

    32k GitHub starsUsed in 3 repos~2.6k tokens
    DatabasesAuto-check passed
  • Cloudflare D1

    alinaqi/maggy

    Cloudflare D1 SQLite database with Workers, Drizzle ORM, migrations

    707 GitHub stars~4.1k tokensUpdated 13 days ago
    DatabasesAuto-check passed
  • Database Fundamentals

    DanielPodolsky/ownyourcode

    Reviews schema design, SQL queries, ORM patterns. An agent skill from DanielPodolsky/ownyourcode.

    290 GitHub starsUsed in 1 repo~1.6k tokens
    DatabasesAuto-check passed
  • Basin

    cloudflare/skills

    Official

    Build and troubleshoot Cloudflare Basin analytics workflows with Basin Pipelines, Basin Catalog, and Basin SQL.

    3k GitHub starsUsed in 1 repo~684 tokens
    DatabasesAuto-check passed
  • DB Migrations

    kurealnum/dotfiles

    A skill your agent uses when generating or regenerating Drizzle migration files, changing database schema tables or columns, resolving migration sequence conflicts after rebase, reviewing migration…

    290 GitHub stars~820 tokensUpdated 5 mo ago
    DatabasesAuto-check passed

More from secondsky/claude-skills

All 169 skills in this repo
  • Tanstack AI

    secondsky/claude-skills

    TanStack AI (alpha) provider-agnostic type-safe chat with streaming for OpenAI, Anthropic, Gemini, Ollama.

    227 GitHub starsUsed in 1 repo~3.6k tokens
    Auto-check: notes
  • Auto Animate

    secondsky/claude-skills

    AutoAnimate (@formkit/auto-animate) zero-config animations for React.

    227 GitHub stars~2.9k tokensUpdated 9 days ago
    Auto-check passed
  • Base UI React

    secondsky/claude-skills

    MUI Base UI unstyled React components with Floating UI. An agent skill from secondsky/claude-skills.

    227 GitHub stars~1.9k tokensUpdated 9 days ago
    Auto-check passed
  • Cloudflare Images

    secondsky/claude-skills

    This skill should be used when the user asks to "upload images to Cloudflare", "implement direct creator upload", "configure image transformations", "optimize WebP/AVIF", "create image variants"…

    227 GitHub stars~3.6k tokensUpdated 9 days ago
    Auto-check: notes
  • Cloudflare Nextjs

    secondsky/claude-skills

    Deploy Next.js to Cloudflare Workers via the OpenNext adapter (@opennextjs/cloudflare).

    227 GitHub stars~5.3k tokensUpdated 9 days ago
    Auto-check: notes
  • Cloudflare Sandbox

    secondsky/claude-skills

    Cloudflare Sandboxes SDK for secure code execution in Linux containers at edge.

    227 GitHub stars~4.5k tokensUpdated 9 days ago
    Auto-check passed

Categories

Questions about Drizzle Orm D1

What does Drizzle Orm D1 do?

| Type-safe ORM for Cloudflare D1 databases using Drizzle. An agent skill from secondsky/claude-skills. Drizzle Orm D1 is an agent skill from secondsky/claude-skills. | Type-safe ORM for Cloudflare D1 databases using Drizzle.

When should I use Drizzle Orm D1?

Drizzle Orm D1 fits situations like: : building D1 database schemas; writing type-safe SQL queries; managing migrations with Drizzle Kit; defining table relations.

How do I install Drizzle Orm D1 in Claude Code?

Run `npx skills add secondsky/claude-skills --skill drizzle-orm-d1 -a claude-code`. Or copy the skill folder (plugins/drizzle-orm-d1/skills/drizzle-orm-d1 in secondsky/claude-skills) into .claude/skills/drizzle-orm-d1 in your project. Claude Code loads it when a task matches its description.

How do I install Drizzle Orm D1 in Codex?

Run `npx skills add secondsky/claude-skills --skill drizzle-orm-d1 -a codex`. Or copy the skill folder (plugins/drizzle-orm-d1/skills/drizzle-orm-d1 in secondsky/claude-skills) into .agents/skills/drizzle-orm-d1 in your project. Codex loads it when a task matches its description.

Can I use Drizzle Orm D1 in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add secondsky/claude-skills --skill drizzle-orm-d1 -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/drizzle-orm-d1, .gemini/skills/drizzle-orm-d1, .github/skills/drizzle-orm-d1 and .opencode/skills/drizzle-orm-d1 in your project.

What does Drizzle Orm D1 need to run?

Going by SKILL.md and its folder, Drizzle Orm D1 needs TypeScript and a shell for the scripts in its folder, the command-line tools its instructions call (npm, bunx, bun and wrangler) and credentials named CLOUDFLARE_D1_TOKEN. Our summary lists: Node.js; A Bash shell; A credential in CLOUDFLARE_D1_TOKEN.

Does Drizzle Orm D1 access the network?

SKILL.md names 2 domains. As links in the text: orm.drizzle.team and github.com. This is read from the text; nothing was executed.

Is Drizzle Orm D1 safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. The check reads SKILL.md only: the scripts in the folder are not scanned, so read them before running anything.

What licence does Drizzle Orm D1 use?

Drizzle Orm D1 is published under the MIT licence (declared in SKILL.md). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Drizzle Orm D1 use?

About 2.4k tokens (SKILL.md is roughly 9.4k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full. Its references folder adds about 7.1k tokens, read only when the agent opens those files.

What are the alternatives to Drizzle Orm D1?

Skills that share tags, products or a category with Drizzle Orm D1: Drizzle Orm (growupanand/ConvoForm, 101 stars), Drizzle Orm Expert (davila7/claude-code-templates, 32k stars), Cloudflare D1 (alinaqi/maggy, 707 stars) and Database Fundamentals (DanielPodolsky/ownyourcode, 290 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Drizzle Orm D1?

secondsky (a GitHub user) maintains it in secondsky/claude-skills, which has 227 GitHub stars. The repository holds 169 skills in this directory. The repository was last updated on September 28, 2026.

Source: secondsky/claude-skills on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.