返回顶部
D

Drizzle

Build type-safe database queries with Drizzle ORM patterns.

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.0
安全检测
已通过
1,183
下载量
2
收藏
概述
安装方式
版本历史

Drizzle

## Schema Definition - Export every table from schema file — queries fail silently if table isn't exported - Use `$inferSelect` for query return types, `$inferInsert` for insert input — they differ (select has defaults filled, insert has optionals) - Define `relations()` in a separate call, not inline with table — Drizzle separates schema from relations ## Query Syntax Traps - Conditions use functions, not objects: `where: eq(users.id, 5)` not `where: { id: 5 }` — Prisma syntax doesn't work - Combine conditions with `and()` / `or()`: `where: and(eq(users.active, true), gt(users.age, 18))` - `db.query.users.findMany()` for relational queries with `with:`, `db.select().from(users)` for SQL-like — mixing them causes type errors ## Migrations - `drizzle-kit push` is dev-only (destructive) — production needs `drizzle-kit generate` then `drizzle-kit migrate` - Schema changes require regenerating migrations — editing generated SQL breaks the migration hash - Set `strict: true` in drizzle.config.ts to catch schema drift before it hits production ## Driver-Specific - PostgreSQL: use `pgTable`, imports from `drizzle-orm/pg-core` - MySQL: use `mysqlTable`, imports from `drizzle-orm/mysql-core` - SQLite: use `sqliteTable`, imports from `drizzle-orm/sqlite-core` - Mixing imports across drivers compiles but fails at runtime with cryptic errors ## Performance - Wrap multi-query operations in `db.transaction(async (tx) => {})` — Drizzle doesn't auto-batch - Use `.prepare()` for queries executed repeatedly — skips query building overhead - Add `.limit()` to every `findMany()` / `select()` — no default limit means full table scans ## Common Mistakes - Forgetting `await` on queries returns a Promise, not results — TypeScript doesn't catch this if you ignore the return - `returning()` is required to get inserted/updated rows back — without it you get `{ rowCount }` only - JSON columns: PostgreSQL uses `jsonb()`, MySQL uses `json()` — wrong function = wrong serialization

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 drizzle-1776420002 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 drizzle-1776420002 技能

通过命令行安装

skillhub install drizzle-1776420002

下载 Zip 包

⬇ 下载 Drizzle v1.0.0

文件大小: 1.69 KB | 发布时间: 2026-4-17 20:22

v1.0.0 最新 2026-4-17 20:22
Initial release

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部