Communitygithub.com

YepAPI/skills

Drizzle 스키마 정의, push vs migrate, 타입 안전 쿼리, 관계, 트랜잭션 및 준비된 구문.

skills란 무엇인가요?

이 스킬은 Drizzle ORM을 사용할 때 개발자와 AI 에이전트가 따라야 할 핵심 규칙과 패턴을 제시합니다. 스키마 정의는 `pgTable()`, `mysqlTable()`, `sqliteTable()`을 사용하여 `src/db/schema.ts` 파일에서 수행하며, 개발 환경에서는 `drizzle-kit push`로 빠르게 반복하고, 프로덕션 환경에서는 `drizzle-kit generate`와 `drizzle-kit migrate`로 추적 가능한 마이그레이션 이력을 관리합니다. 타입 안전 쿼리는 `db.select().from(users).where(eq(users.email, email))`와 같은 풀 타입스크립트 추론을 제공하며, `relations()` 헬퍼를 통해 `one()`과 `many()` 관계를 정의하고 `db.query`로 관계형 쿼리를 수행할 수 있습니다. 또한, 준비된 구문을 자주 사용되는 경로에 재사용하고, 트랜잭션은 `db.transaction(async (tx) => { ... })` 패턴을 따릅니다. 이 스킬은 Cursor, Codex, Claude Code와 같은 AI 코딩 도구에서 Drizzle ORM을 올바르게 활용하는 데 도움을 줍니다.

지원 대상~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/YepAPI/skills/tree/HEAD/skills/drizzle-orm

즐겨 사용하는 AI에게 물어보기

이 에이전트 스킬이 미리 로드된 새 채팅을 엽니다.

문서

Drizzle ORM

규칙

  • 스키마 정의: src/db/schema.ts에서 pgTable() / mysqlTable() / sqliteTable() 사용
  • 개발: 빠른 반복을 위해 drizzle-kit push 사용 — 마이그레이션 파일 불필요
  • 프로덕션: 추적 가능한 마이그레이션 이력을 위해 drizzle-kit generate + drizzle-kit migrate 사용
  • 타입 안전 쿼리: db.select().from(users).where(eq(users.email, email)) — 전체 TypeScript 추론
  • 관계: relations() 헬퍼로 정의 — one()과 many()를 사용하여 db.query로 관계형 쿼리
  • 준비된 구문: db.select().from(users).where(eq(users.id, sql.placeholder("id"))).prepare() — 자주 사용되는 경로에 재사용
  • 트랜잭션: db.transaction(async (tx) => { ... }) — 콜백 내부에서는 tx를 사용하고 db를 사용하지 않음
  • 인덱스: .index()로 인라인 정의하거나 테이블 설정에서 정의 — where 및 orderBy에 사용되는 열에 추가
  • Drizzle Studio: 개발 중 시각적 데이터베이스 브라우저를 위해 npx drizzle-kit studio 실행

패턴

// schema.ts
import { pgTable, text, timestamp, uuid, integer } from "drizzle-orm/pg-core";
import { relations } from "drizzle-orm";

export const users = pgTable("users", {
  id: uuid("id").primaryKey().defaultRandom(),
  name: text("name").notNull(),
  email: text("email").notNull().unique(),
  createdAt: timestamp("created_at").defaultNow().notNull(),
});

export const posts = pgTable("posts", {
  id: uuid("id").primaryKey().defaultRandom(),
  title: text("title").notNull(),
  authorId: uuid("author_id").references(() => users.id).notNull(),
});

export const usersRelations = relations(users, ({ many }) => ({
  posts: many(posts),
}));

export const postsRelations = relations(posts, ({ one }) => ({
  author: one(users, { fields: [posts.authorId], references: [users.id] }),
}));

// 관계 쿼리
const result = await db.query.users.findFirst({
  where: eq(users.id, userId),
  with: { posts: true },
});

피해야 할 것

  • 프로덕션에서 drizzle-kit push 사용 — 추적 가능한 마이그레이션을 위해 generate + migrate 사용
  • Drizzle API가 처리할 수 있는 경우 원시 SQL 사용 — 복잡한 표현식에만 sql 템플릿 태그 사용
  • relations() 정의 누락 — 없으면 db.query 관계형 쿼리가 작동하지 않음
  • N+1 쿼리 — db.query에서 with를 사용하여 단일 쿼리로 관계 조인
  • 외래 키 및 필터링된 열에 인덱스 누락 — Drizzle은 자동으로 생성하지 않음

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

YepAPI/skills

WCAG 2.1 AA — semantic HTML, keyboard navigation, screen readers.

YepAPI/skills

Experiment setup, variant splitting, statistical significance, and feature flag integration.

YepAPI/skills

CRUD generators, data tables, user management, role-based access, and bulk operations.

YepAPI/skills

Monitor what ChatGPT and Gemini say about your brand using YepAPI.

YepAPI/skills

Queue workers with BullMQ/Inngest/Trigger.dev, job retries, dead letter queues, concurrency.

YepAPI/skills

Commander.js, interactive prompts with Clack, spinners, colors, config files, exit codes, and npm publishing.

YepAPI/skills

cmdk integration, Cmd+K trigger, fuzzy search, grouped actions, keyboard navigation, and dynamic action registration.

YepAPI/skills

Content planning with trend and sentiment data from YepAPI.

YepAPI/skills

Content calendar, keyword-driven planning, and content briefs.

YepAPI/skills

Theme switching with CSS variables, system preference detection, next-themes, and persistence.

YepAPI/skills

Threaded comments, @mentions, reactions, moderation queue, optimistic UI, and cursor pagination.

YepAPI/skills

Competitive analysis between domains using YepAPI.

YepAPI/skills

Layout grids, KPI cards, data tables with sorting/filtering, sidebar navigation, and responsive breakpoints.

YepAPI/skills

Data encryption — TLS everywhere, AES-256-GCM for PII, bcrypt passwords, encrypted backups.

YepAPI/skills

Chart patterns with Recharts/Nivo/D3, responsive containers, color scales, and accessibility.

YepAPI/skills

Upload handling, resize/compress, CDN delivery, blur placeholders, and next/image patterns.

YepAPI/skills

Local business and Google Maps research using YepAPI.

YepAPI/skills

Cursor-based pagination, IntersectionObserver, virtualized lists with @tanstack/react-virtual, and scroll position restoration.

YepAPI/skills

Tenant isolation (row-level vs schema), subdomain routing, per-tenant config, and data partitioning.

YepAPI/skills

Chat UI components, streaming responses with AI SDK, context window management, and RAG patterns.

관련 스킬