skills/barnhardt-enterprises-inc/drizzle-patterns/SKILL.md
Drizzle ORM patterns for PostgreSQL.
npx skillsauth add aiskillstore/marketplace drizzle-patternsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
// 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: '[email protected]',
name: 'Test User',
}).returning();
// Insert many
await db.insert(users).values([
{ email: '[email protected]', name: 'User 1' },
{ email: '[email protected]', 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!,
},
});
development
Apple Human Interface Guidelines for content display components. Use this skill when the user asks about charts component, collection view, image view, web view, color well, image well, activity view, lockup, data visualization, content display, displaying images, rendering web content, color pickers, or presenting collections of items in Apple apps. Also use when the user says how should I display charts, what's the best way to show images, should I use a web view, how do I build a grid of items, what component shows media, or how do I present a share sheet. Cross-references: hig-foundations for color/typography/accessibility, hig-patterns for data visualization patterns, hig-components-layout for structural containers, hig-platforms for platform-specific component behavior.
tools
Automate HelpDesk tasks via Rube MCP (Composio): list tickets, manage views, use canned responses, and configure custom fields. Always search tools first for current schemas.
testing
Expert Haskell engineer specializing in advanced type systems, pure functional design, and high-reliability software. Use PROACTIVELY for type-level programming, concurrency, and architecture guidance.
tools
GraphQL gives clients exactly the data they need - no more, no less. One endpoint, typed schema, introspection. But the flexibility that makes it powerful also makes it dangerous. Without proper controls, clients can craft queries that bring down your server. This skill covers schema design, resolvers, DataLoader for N+1 prevention, federation for microservices, and client integration with Apollo/urql. Key insight: GraphQL is a contract. The schema is the API documentation. Design it carefully.