Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

drizzle-orm

БесплатноБез исполняемых скриптовНе проверен

Drizzle ORM is a lightweight, type-safe TypeScript ORM whose query builder maps directly to SQL, with a companion CLI (drizzle-kit) that generates and applies…

TerminalSkillsот TerminalSkills★ 221 звезда на GitHub

Об этом скилле

Drizzle ORM — TypeScript SQL That Feels Like SQL

Overview

Drizzle is a TypeScript ORM with no runtime query engine: the schema is plain TypeScript, queries compile to SQL strings, and result types are inferred from the schema. It supports PostgreSQL, MySQL, SQLite and SingleStore families, including serverless drivers (Neon, Turso/libSQL, Cloudflare D1, PGlite). Two query styles exist side by side: the SQL-like builder (db.select().from()) and the relational API (db.query.users.findMany({ with })).

drizzle-orm (runtime) and drizzle-kit (CLI for migrations and Studio) are versioned separately. This skill covers the stable line, [email protected] and [email protected]. A 1.0 release candidate is published under the rc npm tag (it changes the relational API, "RQB v2"); do not install it unless the project already uses it.

Instructions

Install

npm install drizzle-orm pg
npm install -D drizzle-kit tsx @types/pg
# other drivers: mysql2, better-sqlite3, @libsql/client, @neondatabase/serverless, @electric-sql/pglite

Schema

Column names can be omitted when casing is set (camelCase key becomes snake_case column). Index and constraint callbacks return an array; the older object-returning form is deprecated.

// src/schema.ts
import { relations } from "drizzle-orm";
import { boolean, index, integer, jsonb, pgTable, text, timestamp, uniqueIndex, uuid, varchar } from "drizzle-orm/pg-core";

export const users = pgTable("users", {
  id: uuid().primaryKey().defaultRandom(),
  name: varchar({ length: 255 }).notNull(),
  email: varchar({ length: 255 }).notNull(),
  role: varchar({ length: 20 }).notNull().default("user"),
  metadata: jsonb().$type<{ plan: string; seats: number }>(),
  createdAt: timestamp().defaultNow().notNull(),
}, (t) => [uniqueIndex("users_email_idx").on(t.email)]);

export const posts = pgTable("posts", {
  id: integer().primaryKey().generatedAlwaysAsIdentity(),
  title: varchar({ length: 500 }).notNull(),
  content: text(),
  published: boolean().default(false).notNull(),
  authorId: uuid().references(() => users.id, { onDelete: "cascade" }).notNull(),
  createdAt: timestamp().defaultNow().notNull(),
}, (t) => [
  index("posts_author_idx").on(t.authorId),
  index("posts_published_idx").on(t.published, t.createdAt),
]);

// Relations are only needed for db.query (relational API)
export const usersRelations = relations(users, ({ many }) => ({ posts: many(posts) }));
export const postsRelations = relations(posts, ({ one }) => ({
  author: one(users, { fields: [posts.authorId], references: [users.id] }),
}));

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

Connect

drizzle() accepts a connection string, or an object with client/connection. Pass schema to enable db.query, and the same casing as in the config.

// src/db.ts
import { drizzle } from "drizzle-orm/node-postgres";
import * as schema from "./schema";

export const db = drizzle(process.env.DATABASE_URL!, { schema, casing: "snake_case" });
// existing pool: drizzle({ client: pool, schema, casing: "snake_case" })

Driver import paths: drizzle-orm/node-postgres, postgres-js, neon-http, neon-serverless, mysql2, better-sqlite3, libsql, d1, pglite, bun-sql.

Queries

import { and, count, desc, eq, gte, sql } from "drizzle-orm";
import { db } from "./db";
import { posts, users } from "./schema";

const recent = await db.select().from(posts)
  .where(and(eq(posts.published, true), gte(posts.createdAt, new Date("2026-01-01"))))
  .orderBy(desc(posts.createdAt)).limit(20);

const withAuthors = await db.select({ title: posts.title, author: users.name })
  .from(posts).innerJoin(users, eq(posts.authorId, users.id));

// Relational API (needs schema passed to drizzle())
const admins = await db.query.users.findMany({
  where: eq(users.role, "admin"),
  with: { posts: { where: eq(posts.published, true), limit: 5 } },
});

const [created] = await db.insert(users).values({ name: "Alice Novak", email: "[email protected]" }).returning();

await db.insert(users).values({ name: "Alice Novak", email: "[email protected]" })
  .onConflictDoUpdate({ target: users.email, set: { name: "Alice N." } });

const [stats] = await db.select({
  total: count(),
  published: count(sql`CASE WHEN ${posts.published} THEN 1 END`),
}).from(posts);

await db.transaction(async (tx) => {
  await tx.update(posts).set({ published: true }).where(eq(posts.title, "Draft"));
});

// Prepared statement with a named placeholder
const byAuthor = db.select().from(posts).where(eq(posts.authorId, sql.placeholder("authorId"))).prepare("posts_by_author");
await byAuthor.execute({ authorId: created.id });

Migrations with drizzle-kit

// drizzle.config.ts
import { defineConfig } from "drizzle-kit";

export default defineConfig({
  dialect: "postgresql",          // postgresql | mysql | sqlite | turso
Полный SKILL.md на GitHub

Установить drizzle-orm в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

_scores.json

FAQ

Что делает скилл drizzle-orm?

Drizzle ORM is a lightweight, type-safe TypeScript ORM whose query builder maps directly to SQL, with a companion CLI (drizzle-kit) that generates and applies migrations. Use when a user asks to define a database schema in TypeScript, write typed Postgres, MySQL or SQLite queries, run drizzle-kit generate, migrate or push, or connect Drizzle to Neon, Turso, Cloudflare D1, PGlite or node-postgres.

Как установить скилл drizzle-orm?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл drizzle-orm запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить drizzle-orm с