Drizzle ORM
БесплатноБез исполняемых скриптовНе проверенExpert guidance for Drizzle ORM including schema definition, queries, relations, migrations, TypeScript integration with SQLite/PostgreSQL, and Drizzle…
Об этом скилле
Drizzle ORM
Expert assistance with Drizzle ORM - TypeScript ORM for SQL databases.
Overview
Drizzle ORM is a lightweight TypeScript ORM:
- Type-Safe: Full TypeScript type inference
- SQL-Like: Familiar SQL syntax, not a new query language
- Performant: Zero overhead, generates efficient SQL
- Multiple Databases: PostgreSQL, MySQL, SQLite support
- Migrations: Built-in migration system
- Drizzle Studio: Visual database browser
Installation
# Core packages
npm install drizzle-orm
npm install --save-dev drizzle-kit
# Database driver (choose one)
npm install better-sqlite3 # For SQLite
npm install @types/better-sqlite3 --save-dev
# Or for PostgreSQL
npm install postgres # For PostgreSQL
npm install pg # Alternative PostgreSQL driver
Quick Start (SQLite)
1. Define Schema
// src/db/schema.ts
import { sqliteTable, text, integer } from 'drizzle-orm/sqlite-core';
export const users = sqliteTable('users', {
id: text('id').primaryKey(),
name: text('name').notNull(),
email: text('email').notNull().unique(),
createdAt: integer('created_at', { mode: 'timestamp' }).notNull().$defaultFn(() => new Date()),
});
export const posts = sqliteTable('posts', {
id: text('id').primaryKey(),
title: text('title').notNull(),
content: text('content').notNull(),
userId: text('user_id').notNull().references(() => users.id, { onDelete: 'cascade' }),
createdAt: integer('created_at', { mode: 'timestamp' }).notNull().$defaultFn(() => new Date()),
});
2. Create Database Client
// src/db/client.ts
import { drizzle } from 'drizzle-orm/better-sqlite3';
import Database from 'better-sqlite3';
import * as schema from './schema';
const sqlite = new Database('sqlite.db');
export const db = drizzle(sqlite, { schema });
3. Use in Application
import { db } from './db/client';
import { users, posts } from './db/schema';
import { eq } from 'drizzle-orm';
// Insert
const newUser = await db.insert(users).values({
id: '1',
name: 'John Doe',
email: '[email protected]',
}).returning();
// Query
const allUsers = await db.select().from(users);
const user = await db.select().from(users).where(eq(users.id, '1'));
// Update
await db.update(users)
.set({ name: 'Jane Doe' })
.where(eq(users.id, '1'));
// Delete
await db.delete(users).where(eq(users.id, '1'));
Schema Definition
Column Types (SQLite)
import { sqliteTable, text, integer, real, blob } from 'drizzle-orm/sqlite-core';
export const examples = sqliteTable('examples', {
// Text
id: text('id').primaryKey(),
name: text('name').notNull(),
description: text('description'),
// Integer
age: integer('age'),
count: integer('count').default(0),
// Boolean (stored as integer 0/1)
isActive: integer('is_active', { mode: 'boolean' }).default(true),
// Timestamp (stored as integer unix epoch)
createdAt: integer('created_at', { mode: 'timestamp' }),
updatedAt: integer('updated_at', { mode: 'timestamp_ms' }), // milliseconds
// Real (floating point)
price: real('price'),
// Blob (binary data)
data: blob('data', { mode: 'buffer' }),
// JSON (stored as text)
metadata: text('metadata', { mode: 'json' }).$type<{ key: string; value: number }>(),
});
Constraints
import { sqliteTable, text, integer, primaryKey, unique index } from 'drizzle-orm/sqlite-core';
export const users = sqliteTable('users', {
id: text('id').primaryKey(),
email: text('email').notNull().unique(), // Unique constraint
name: text('name').notNull(), // Not null
age: integer('age').default(18), // Default value
}, (table) => ({
// Composite unique constraint
emailNameUnique: unique().on(table.email, table.name),
// Index
emailIdx: index('email_idx').on(table.email),
// Composite index
nameAgeIdx: index('name_age_idx').on(table.name, table.age),
}));
// Composite primary key
export const userRoles = sqliteTable('user_roles', {
userId: text('user_id').notNull(),
roleId: text('role_id').notNull(),
}, (table) => ({
pk: primaryKey({ columns: [table.userId, table.roleId] }),
}));
Check Constraints
import { sql } from 'drizzle-orm';
import { sqliteTable, text, integer, check } from 'drizzle-orm/sqlite-core';
export const certificates = sqliteTable('certificates', {
id: text('id').primaryKey(),
status: text('status').notNull(),
serialNumber: text('serial_number').notNull(),
}, (table) => ({
// Check constraint
statusCheck: check('status_check', sql`${table.status} IN ('active', 'revoked', 'expired')`),
}));
Foreign Keys
export const posts = sqliteTable('posts', {
id: text('id').primaryKey(),
userId: text('user_id')
.notNull()
.references(() => users.id, {
onDelete: 'cascade', // Delete posts when user is deleted
onUpdate: 'cascade', // Update posts when us
Установить Drizzle ORM в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл Drizzle ORM?
Expert guidance for Drizzle ORM including schema definition, queries, relations, migrations, TypeScript integration with SQLite/PostgreSQL, and Drizzle Studio. Use this when working with type-safe database operations, schema management, or ORM queries.
Как установить скилл Drizzle ORM?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл Drizzle ORM запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic