Drizzle ORM patterns for PostgreSQL.
Provides Drizzle ORM patterns for PostgreSQL including schema definitions, relations, queries, mutations, and transactions. Use when building Node.js apps with PostgreSQL to scaffold database layers with proper TypeScript types and relation handling.
/plugin marketplace add barnent1/quetrex-claude/plugin install quetrex-claude@quetrexThis skill inherits all available tools. When active, it can use any tool Claude has access to.
// db/schema/users.ts
import { pgTable, uuid, varchar, timestamp, boolean } from 'drizzle-orm/pg-core';
export const users = pgTable('users', {
id: uuid('id').primaryKey().defaultRandom(),
email: varchar('email', { length: 255 }).notNull().unique(),
name: varchar('name', { length: 255 }),
emailVerified: boolean('email_verified').default(false),
createdAt: timestamp('created_at').defaultNow().notNull(),
updatedAt: timestamp('updated_at').defaultNow().notNull(),
});
export type User = typeof users.$inferSelect;
export type NewUser = typeof users.$inferInsert;
// db/schema/relations.ts
import { relations } from 'drizzle-orm';
import { users } from './users';
import { posts } from './posts';
export const usersRelations = relations(users, ({ many }) => ({
posts: many(posts),
}));
export const postsRelations = relations(posts, ({ one }) => ({
author: one(users, {
fields: [posts.authorId],
references: [users.id],
}),
}));
// db/index.ts
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 });
import { eq, and, or, like, desc, asc } from 'drizzle-orm';
// Find one
const user = await db.query.users.findFirst({
where: eq(users.id, userId),
});
// Find many with relations
const usersWithPosts = await db.query.users.findMany({
with: { posts: true },
where: eq(users.emailVerified, true),
orderBy: [desc(users.createdAt)],
limit: 10,
});
// Complex where
const results = await db.query.posts.findMany({
where: and(
eq(posts.published, true),
or(
like(posts.title, '%search%'),
like(posts.content, '%search%')
)
),
});
// Insert
const [newUser] = await db.insert(users).values({
email: 'test@example.com',
name: 'Test User',
}).returning();
// Insert many
await db.insert(users).values([
{ email: 'user1@example.com', name: 'User 1' },
{ email: 'user2@example.com', name: 'User 2' },
]);
// Update
await db.update(users)
.set({ name: 'New Name', updatedAt: new Date() })
.where(eq(users.id, userId));
// Delete
await db.delete(users)
.where(eq(users.id, userId));
await db.transaction(async (tx) => {
const [user] = await tx.insert(users).values(userData).returning();
await tx.insert(profiles).values({ userId: user.id, ...profileData });
await tx.insert(settings).values({ userId: user.id, ...defaultSettings });
});
# Generate migration
pnpm drizzle-kit generate
# Push to database
pnpm drizzle-kit push
# Open Drizzle Studio
pnpm drizzle-kit studio
import { defineConfig } from 'drizzle-kit';
export default defineConfig({
schema: './db/schema/index.ts',
out: './db/migrations',
dialect: 'postgresql',
dbCredentials: {
url: process.env.DATABASE_URL!,
},
});
This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.