drizzle-orm-rules
БесплатноЗапускает вложенные скриптыНе проверенRules for Drizzle ORM schema design, query patterns, migration workflows, and relational query usage. Ensures type-safe, production-ready database interactions.
от oimiragieo★ 48 звёзд на GitHubОб этом скилле
Drizzle ORM Rules Skill
Schema Design
- Use
integer('id').primaryKey().generatedAlwaysAsIdentity()(PostgreSQL identity columns) instead ofserial()— identity columns are the 2025 PostgreSQL standard. - Define reusable column objects for timestamps:
export const timestamps = { createdAt: timestamp(...).defaultNow().notNull(), updatedAt: timestamp(...).$onUpdateFn(() => new Date()) }. - Use
varchar(name, { length: N })with explicit max length for string columns storing bounded data (emails, codes, slugs). - Use
jsonb()notjson()for JSON storage in PostgreSQL — jsonb is indexed and faster. - Always call
.notNull()on columns that must not be nullable.
Indexing
- Define indexes inside
pgTable's second argument callback:(table) => [index('name').on(table.col)]. - Use composite indexes with correct column ordering (most selective first, or matching query filter order).
- Use
uniqueIndex()for unique constraints on single or combined columns. - For full-text search, use
.withSearchIndexor a GIN index via raw SQL migration.
Queries
- Prefer
db.query.<table>.findMany({ with: { relation: true } })(relational API) for typed nested joins. - Use
db.select().from(table).where(eq(table.col, val))for flat queries. - Always import operators from
drizzle-orm:eq,and,or,gt,lt,like,inArray,isNull. - Use
db.transaction(async (tx) => {...})for multi-step writes that must be atomic. - Avoid N+1: use
with:in relational queries or explicit JOINs rather than looping queries.
Migrations
- Local development:
drizzle-kit push(fast, no migration files) — never for production. - Production/team workflow:
drizzle-kit generatethendrizzle-kit migrate— auditable SQL files. - Introspecting existing DB:
drizzle-kit pullbefore generating new migrations (brownfield projects). - Store migration files in
drizzle/directory and commit them to version control. - Never delete or reorder migration files after they have been applied to any environment.
Relations
- Define explicit
relations()alongside table definitions inschema.ts. - Use
one()for many-to-one references andmany()for one-to-many or many-to-many. - Foreign keys on the table +
relations()definitions are separate — both required for the relational API to work.
// Reusable timestamp columns export const timestamps = { createdAt: timestamp('created_at', { mode: 'date', withTimezone: true }).defaultNow().notNull(), updatedAt: timestamp('updated_at', { mode: 'date', withTimezone: true }) .defaultNow() .notNull() .$onUpdateFn(() => new Date()), };
export const users = pgTable('users', { id: integer('id').primaryKey().generatedAlwaysAsIdentity(), // NOT serial email: varchar('email', { length: 320 }).notNull().unique(), name: text('name').notNull(), meta: jsonb('meta'), // jsonb, not json ...timestamps, }, (table) => [ index('users_email_idx').on(table.email), ]);
export const posts = pgTable('posts', { id: integer('id').primaryKey().generatedAlwaysAsIdentity(), userId: integer('user_id').notNull().references(() => users.id), title: varchar('title', { length: 500 }).notNull(), ...timestamps, }, (table) => [ index('posts_user_id_idx').on(table.userId), ]);
// Relations (required for relational query API) export const usersRelations = relations(users, ({ many }) => ({ posts: many(posts), })); export const postsRelations = relations(posts, ({ one }) => ({ user: one(users, { fields: [posts.userId], references: [users.id] }), }));
// src/lib/db/queries.ts — typed relational query import { db } from './client'; import { eq } from 'drizzle-orm'; import { users } from './schema';
export async function getUserWithPosts(userId: number) { return db.query.users.findFirst({ where: eq(users.id, userId), with: { posts: true }, // nested join — no N+1 }); }
// Atomic transaction ex
Установить drizzle-orm-rules в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
ReadWriteEditВложенные файлы
FAQ
Что делает скилл drizzle-orm-rules?
Rules for Drizzle ORM schema design, query patterns, migration workflows, and relational query usage. Ensures type-safe, production-ready database interactions.
Как установить скилл drizzle-orm-rules?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл drizzle-orm-rules запускает скрипты?
Да, скилл несёт исполняемые скрипты. Проверь исходник перед установкой.
Похожие скиллы
frontend-design
Guidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making…
от Anthropicwebapp-testing
Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing…
от Anthropicbrand-guidelines
Applies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand…
от Anthropicweb-artifacts-builder
Suite of tools for creating elaborate, multi-component claude.ai HTML artifacts using modern frontend web technologies (React, Tailwind CSS, shadcn/ui). Use…
от Anthropic