π¦ ClawHub
Drizzle
by @ivangdavila
Build type-safe database queries with Drizzle ORM patterns.
TERMINAL
clawhub install drizzleπ About This Skill
name: Drizzle description: Build type-safe database queries with Drizzle ORM patterns. metadata: {"clawdbot":{"emoji":"π§","requires":{"bins":["npx"]},"os":["linux","darwin","win32"]}}
Schema Definition
$inferSelect for query return types, $inferInsert for insert input β they differ (select has defaults filled, insert has optionals)relations() in a separate call, not inline with table β Drizzle separates schema from relationsQuery Syntax Traps
where: eq(users.id, 5) not where: { id: 5 } β Prisma syntax doesn't workand() / 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 errorsMigrations
drizzle-kit push is dev-only (destructive) β production needs drizzle-kit generate then drizzle-kit migratestrict: true in drizzle.config.ts to catch schema drift before it hits productionDriver-Specific
pgTable, imports from drizzle-orm/pg-coremysqlTable, imports from drizzle-orm/mysql-core sqliteTable, imports from drizzle-orm/sqlite-corePerformance
db.transaction(async (tx) => {}) β Drizzle doesn't auto-batch.prepare() for queries executed repeatedly β skips query building overhead.limit() to every findMany() / select() β no default limit means full table scansCommon Mistakes
await on queries returns a Promise, not results β TypeScript doesn't catch this if you ignore the returnreturning() is required to get inserted/updated rows back β without it you get { rowCount } onlyjsonb(), MySQL uses json() β wrong function = wrong serialization