Token导航 LogoToken导航TokenDH.com
研究检索需要联网github未标认证来源可访问clear审计通过

drizzle-ormDrizzle ORM

Agent Skill

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

总安装

7,109

周安装

303

GitHub Stars

88

下载量

3,518
CodexClaudeCursorGemini CLI

安装说明

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

GitHub

来源数

3

许可证

MIT

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

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

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

命令行安装

复制命令到本机终端执行。不同来源提供的安装方式可能略有差异;本站展示可直接复制的安装命令,安装前请核对来源页面。

skills.shnpx skills
npx skills add https://github.com/blockmatic/basilic --skill 'Drizzle ORM'

简介

Drizzle ORM v0.44+ 的官方支持技能,助力 PostgreSQL/MySQL/SQLite 数据建模。

  • 提供 schema 定义、关系映射、迁移脚本生成与类型安全查询编写指导。
  • 强调 dry-run 优先原则,重大变更前务必备份数据库并启用事务保护。
  • 不支持驱动配置与连接池设置,需另行处理基础设施层问题。
  • drizzle-orm 属于研究检索类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

Skill: drizzle-orm

Scope

  • Applies to: Drizzle ORM v0.44+ for PostgreSQL, MySQL, SQLite - schema definitions, type-safe queries, migrations, relations
  • Does NOT cover: Database driver setup, connection pooling configuration, other ORMs

Assumptions

  • Drizzle ORM v0.44+
  • Drizzle Kit v0.31+ (dev dependency) for migrations
  • PostgreSQL, MySQL, or SQLite database
  • TypeScript v5+ with strict mode
  • ESM module system

Principles

  • Schemas defined using table builders (pgTable, mysqlTable, sqliteTable) with typed columns
  • Column types match database constraints (varchar with length, timestamp with mode)
  • Indexes defined in table definition second parameter using index() helper
  • Identity columns (generatedAlwaysAsIdentity) preferred over serial in PostgreSQL
  • Query helpers (eq, and, or, like) provide type-safe SQL construction
  • Relational query builder (db.query.*) preferred for complex relations
  • Type inference via $inferSelect and $inferInsert eliminates manual types
  • Migrations generated with drizzle-kit generate (not push in production)
  • Prepared statements optimize frequently executed queries
  • Schemas organized by domain (one file per entity/table)
  • Transactions (db.transaction) ensure atomic multi-step operations

Constraints

MUST

  • Use Drizzle Kit for migrations (drizzle-kit generate, drizzle-kit migrate)
  • Define column types matching database constraints
  • Use query helpers instead of raw SQL

SHOULD

  • Use relations for type-safe joins
  • Use relational query builder for complex relations
  • Use transactions for multi-step operations
  • Use prepared statements for frequently executed queries
  • Export types via $inferSelect and $inferInsert
  • Handle DrizzleQueryError for structured error handling
  • Organize schemas by domain (one file per entity)
  • Use selective field loading (not full rows)
  • Use identity columns over serial in PostgreSQL
  • Specify length for varchar columns
  • Use index() helper in table definitions
  • Use PGLite for testing PostgreSQL schemas

AVOID

  • Raw SQL unless necessary
  • Manual type assertions (use inferred types)
  • Skipping migration generation
  • serial in new PostgreSQL tables (use identity columns)
  • Over-indexing (index only where queries justify)
  • Fetching full rows when only few columns needed
  • push in production (use generate + migrate)
  • String-based timestamp mode when DB supports date/time types

Interactions

  • Works with nextjs Server Components and API routes
  • Complements fastify for API development

Patterns

Schema Definition

import { index, pgTable, text, timestamp, varchar } from 'drizzle-orm/pg-core'

export const users = pgTable(
  'users',
  {
    id: text('id').primaryKey(),
    email: varchar('email', { length: 255 }).notNull().unique(),
    createdAt: timestamp('created_at').defaultNow().notNull(),
    updatedAt: timestamp('updated_at').defaultNow().notNull(),
  },
  table => [index('users_email_idx').on(table.email)],
)

export type User = typeof users.$inferSelect
export type NewUser = typeof users.$inferInsert

Identity Columns

import { pgTable, integer, generatedAlwaysAsIdentity } from 'drizzle-orm/pg-core'

export const posts = pgTable('posts', {
  id: integer('id').primaryKey().generatedAlwaysAsIdentity(),
})

Query Builder

import { eq } from 'drizzle-orm'

const user = await db
  .select()
  .from(users)
  .where(eq(users.id, userId))
  .limit(1)

const userWithPosts = await db.query.users.findFirst({
  where: eq(users.id, userId),
  with: { posts: true },
})

const userEmail = await db
  .select({ email: users.email })
  .from(users)
  .where(eq(users.id, userId))

Transactions

await db.transaction(async (tx) => {
  const [user] = await tx.insert(users).values(userData).returning()
  await tx.insert(profiles).values({ userId: user.id, ...profileData })
})

Prepared Statements

import { placeholder } from 'drizzle-orm'

const getUserByEmail = db
  .select()
  .from(users)
  .where(eq(users.email, placeholder('email')))
  .prepare('get_user_by_email')

const user = await getUserByEmail.execute({ email: 'user@example.com' })

Error Handling

import { DrizzleQueryError } from 'drizzle-orm'

try {
  const user = await db.select().from(users).where(eq(users.id, userId))
} catch (error) {
  if (error instanceof DrizzleQueryError) {
    if (error.cause?.code === '23505') {
      throw new Error('User already exists')
    }
  }
  throw error
}

Relations

import { relations } from 'drizzle-orm'

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

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

Database Connection

import { drizzle } from 'drizzle-orm/node-postgres'
import { Pool } from 'pg'
import * as schema from './schema'

const pool = new Pool({ connectionString: process.env.DATABASE_URL })
export const db = drizzle(pool, { schema })

Drizzle Kit Config

import { defineConfig } from 'drizzle-kit'

export default defineConfig({
  dialect: 'postgresql',
  schema: './src/db/schema/index.ts',
  out: './src/db/migrations',
  dbCredentials: { url: process.env.DATABASE_URL! },
  migrations: {
    table: '__drizzle_migrations',
    schema: 'public',
  },
  verbose: true,
  strict: true,
})

References

适合场景

01

用户想查找某类 Agent Skill 时

02

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

03

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

04

需要参考平台分布和安装热度时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

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

能力 4

补充不同宿主或平台的使用分布数据

能力 5

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

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

平台分布

Claude Code

25.51%
按下载量换算897

windsurf

25.18%
按下载量换算886

trae

18.36%
按下载量换算646

OpenCode

11.9%
按下载量换算419

Codex

7.71%
按下载量换算271

Antigravity

3.05%
按下载量换算107

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

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

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。来源字段存在多来源差异,先按来源优先级自动处理,无法消解时进入异常复核队列。

来源信息

继续浏览同类 Skills