Token导航 LogoToken导航TokenDH.com
研究检索需要联网github未标认证来源可访问许可证需确认审计异常

drizzle-orm-rulesDrizzle ORM rules 搜索

Agent Skill

用于辅助数据库表结构、查询语句、迁移脚本和数据维护任务。它适合让 Agent 分析 schema、编写 SQL、排查查询问题、整理索引或生成迁移建议。使用时需要明确数据库类型、连接环境和目标表,区分只读分析与写入变更;涉及删除、更新、迁移和批量导入时,应优先 dry-run、备份或事务保护,避免误操作。

总安装

783

周安装

32

GitHub Stars

25

下载量

251
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:drizzle-orm-rules(Drizzle ORM rules 搜索)
来源仓库:https://github.com/oimiragieo/agent-studio
仓库路径:skills/drizzle-orm-rules
安装命令:
npx skills add https://github.com/oimiragieo/agent-studio --skill drizzle-orm-rules
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/oimiragieo/agent-studio --skill drizzle-orm-rules

简介

drizzle-orm-rules 提供 Drizzle ORM 的强制规则集,纠正常见错误如 serial() 与 identity 混用。

  • 强调 varchar 长度约束、jsonb 存储与 timestamp 复用对象,提升 schema 严谨性与性能。
  • 适用于 PostgreSQL 2025 标准实践,支持索引优化与外键约束的正确声明方式。
  • 使用前需确认项目使用最新 Drizzle 版本,避免旧版语法不兼容导致构建失败。
  • 适用宿主包括 Codex、Claude、Cursor、Gemini CLI,接入前应确认版本、权限和运行环境要求。

SKILL.md

Drizzle ORM Rules Skill

Schema Design

  • Use integer('id').primaryKey().generatedAlwaysAsIdentity() (PostgreSQL identity columns) instead of serial() — 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() not json() 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 .withSearchIndex or 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 generate then drizzle-kit migrate — auditable SQL files.
  • Introspecting existing DB: drizzle-kit pull before 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 in schema.ts.
  • Use one() for many-to-one references and many() 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 example export async function transferData(fromId: number, toId: number, amount: number) {return db.transaction(async (tx) => {await tx.update(accounts).set({balance: sqlbalance - ${amount}}).where(eq(accounts.id, fromId)); await tx.update(accounts).set({balance: sqlbalance + ${amount}}).where(eq(accounts.id, toId));});}

</examples>

## Iron Laws

1. **ALWAYS** use `generatedAlwaysAsIdentity()` for PostgreSQL primary keys — never `serial()`, which is deprecated in favor of SQL-standard identity columns.
2. **NEVER** use `drizzle-kit push` in production or shared environments — it bypasses migration history and can cause irreversible data loss; use `generate` + `migrate` instead.
3. **ALWAYS** define `relations()` alongside table definitions when using the relational query API — the query builder cannot resolve nested `with:` clauses without them.
4. **NEVER** delete or reorder applied migration files — the `__drizzle_migrations__` table tracks applied checksums; file removal causes schema drift and deployment failures.
5. **ALWAYS** import query operators (`eq`, `and`, `or`, `gt`, `inArray`, etc.) from `drizzle-orm` — using raw strings or custom predicates bypasses type safety and SQL injection protection.

## Anti-Patterns

| Anti-Pattern | Why It Fails | Correct Approach |
| --- | --- | --- |
| Using `serial()` for primary keys | `serial` is a PostgreSQL pseudo-type implemented via sequences; deprecated since PG 10 in favor of SQL-standard identity columns | Use `integer('id').primaryKey().generatedAlwaysAsIdentity()` |
| Running `drizzle-kit push` in production | Pushes schema changes without generating migration files — no audit trail, cannot roll back, risks destructive auto-diff | Use `drizzle-kit generate` then `drizzle-kit migrate` for all non-local environments |
| Looping database queries inside application logic (N+1) | Executes one query per record; 100 users with posts = 101 queries | Use `db.query.users.findMany({ with: { posts: true } })` to fetch nested data in a single optimized query |
| Omitting `relations()` but using relational query API | Drizzle throws runtime errors when `with:` keys are not mapped via `relations()` | Define `relations()` for every table that participates in relational queries |
| Using `json()` instead of `jsonb()` for JSON columns | `json` stores raw text, cannot be indexed; `jsonb` stores binary, supports GIN indexes and faster operations | Replace `json()` with `jsonb()` for all PostgreSQL JSON columns |

## Memory Protocol (MANDATORY)

**Before starting:**

cat .claude/context/memory/learnings.md


**After completing:** Record any new patterns or exceptions discovered.

> ASSUME INTERRUPTION: Your context may reset. If it's not in memory, it didn't happen.

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

34.92%
按下载量换算88

Claude

30.49%
按下载量换算77

Cursor

20.08%
按下载量换算50

Gemini CLI

8.92%
按下载量换算22

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

未通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。来源安全扫描存在 warning/failed 结果,不能写成本站确认安全。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills