drizzle-patterns
Drizzle ORM patterns for PostgreSQL.
Best use case
drizzle-patterns is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Drizzle ORM patterns for PostgreSQL.
Teams using drizzle-patterns should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/drizzle-patterns/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How drizzle-patterns Compares
| Feature / Agent | drizzle-patterns | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Drizzle ORM patterns for PostgreSQL.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# Drizzle ORM Patterns
## Schema Definition
```typescript
// 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;
```
## Relations
```typescript
// 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],
}),
}));
```
## Database Client
```typescript
// 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 });
```
## Queries
```typescript
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%')
)
),
});
```
## Mutations
```typescript
// 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));
```
## Transactions
```typescript
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 });
});
```
## Migrations
```bash
# Generate migration
pnpm drizzle-kit generate
# Push to database
pnpm drizzle-kit push
# Open Drizzle Studio
pnpm drizzle-kit studio
```
## drizzle.config.ts
```typescript
import { defineConfig } from 'drizzle-kit';
export default defineConfig({
schema: './db/schema/index.ts',
out: './db/migrations',
dialect: 'postgresql',
dbCredentials: {
url: process.env.DATABASE_URL!,
},
});
```Related Skills
castai-sdk-patterns
Production-ready CAST AI REST API wrapper patterns in TypeScript and Python. Use when building reusable CAST AI clients, implementing retry logic, or wrapping the CAST AI API for team use. Trigger with phrases like "cast ai API patterns", "cast ai client wrapper", "cast ai TypeScript", "cast ai Python client".
canva-sdk-patterns
Apply production-ready Canva Connect API client patterns for TypeScript and Python. Use when building a reusable API client, implementing token refresh, or establishing team coding standards for Canva integrations. Trigger with phrases like "canva client patterns", "canva best practices", "canva code patterns", "canva API wrapper", "canva TypeScript client".
canva-reliability-patterns
Implement reliability patterns for Canva Connect API — circuit breakers, idempotency, graceful degradation. Use when building fault-tolerant Canva integrations, implementing retry strategies, or adding resilience to production Canva services. Trigger with phrases like "canva reliability", "canva circuit breaker", "canva resilience", "canva fallback", "canva fault tolerance".
brightdata-sdk-patterns
Apply production-ready Bright Data SDK patterns for TypeScript and Python. Use when implementing Bright Data integrations, refactoring SDK usage, or establishing team coding standards for Bright Data. Trigger with phrases like "brightdata SDK patterns", "brightdata best practices", "brightdata code patterns", "idiomatic brightdata".
bamboohr-sdk-patterns
Apply production-ready BambooHR API patterns for TypeScript and Python. Use when implementing BambooHR integrations, building reusable clients, or establishing team coding standards for BambooHR REST API. Trigger with phrases like "bamboohr SDK patterns", "bamboohr best practices", "bamboohr code patterns", "idiomatic bamboohr", "bamboohr client wrapper".
attio-sdk-patterns
Production-ready patterns for the Attio REST API: typed client, retry with backoff, pagination iterators, and multi-tenant factory. Trigger: "attio SDK patterns", "attio best practices", "attio client wrapper", "idiomatic attio", "attio TypeScript patterns".
assemblyai-sdk-patterns
Apply production-ready AssemblyAI SDK patterns for TypeScript and Python. Use when implementing AssemblyAI integrations, refactoring SDK usage, or establishing team coding standards for transcription workflows. Trigger with phrases like "assemblyai SDK patterns", "assemblyai best practices", "assemblyai code patterns", "idiomatic assemblyai".
apple-notes-sdk-patterns
Apply production-ready patterns for Apple Notes JXA/AppleScript automation. Trigger: "apple notes patterns".
appfolio-sdk-patterns
Apply production-ready patterns for AppFolio REST API integration. Trigger: "appfolio patterns".
apollo-sdk-patterns
Apply production-ready Apollo.io SDK patterns. Use when implementing Apollo integrations, refactoring API usage, or establishing team coding standards. Trigger with phrases like "apollo sdk patterns", "apollo best practices", "apollo code patterns", "idiomatic apollo", "apollo client wrapper".
apify-sdk-patterns
Production-ready patterns for Apify SDK and apify-client in TypeScript. Use when building Actors with Crawlee, managing datasets/KV stores, or implementing robust client wrappers with retry and validation. Trigger: "apify SDK patterns", "apify best practices", "apify client wrapper", "crawlee patterns", "idiomatic apify".
anth-sdk-patterns
Apply production-ready Anthropic SDK patterns for TypeScript and Python. Use when implementing Claude integrations, building reusable wrappers, or establishing team coding standards for the Messages API. Trigger with phrases like "anthropic SDK patterns", "claude best practices", "anthropic code patterns", "production claude code".