with one click
api-database-drizzle
Drizzle ORM, queries, migrations
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Menu
Drizzle ORM, queries, migrations
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Based on SOC occupation classification
Flexible data science analytics for any dataset. Auto-discovers schema, recommends charts, exports to create-figure. Works with JSONL, JSON, CSV from any source.
Use when you have CSV/Excel data files and need PM insights (retention, funnel, segmentation) via Python analysis.
Strategische Markenportfolio-Planung für Luxus-Modehaeuser: Mandant will Marken in DE/EU/international schützen oder Portfolio optimieren. Normen: §§ 32 ff. MarkenG, Art. 32 ff. UMV (EU) 2017/1001, Madrid-Protokoll (WIPO). Prüfraster: Nizza-Klassen (3/14/18/25/35), Multi-Class-Strategie, Prioritaets-Kaskade, Kostenoptimierung, Anmeldezeitpunkt. Output Marken-Portfolio-Plan, Anmelde-Empfehlung je Territorium, Kostenprojektion. Abgrenzung: Einzelne Anmeldung DPMA siehe wortmarke-anmeldung-dpma; Madrid-Protokoll Details siehe madrid-protokoll-und-internationale-registrierung.
Generate comprehensive anomaly detection report with Excel deliverables. Discovers data quality issues without requiring configuration.
Detect data anomalies in Datarails Finance OS tables. Finds outliers, missing values, duplicates, and data quality issues.
PostHog event tracking, user identification, group analytics for B2B, GDPR consent patterns. Use when implementing product analytics, tracking user behavior, setting up funnels, or configuring privacy-compliant tracking.
| name | api-database-drizzle |
| description | Drizzle ORM, queries, migrations |
Quick Guide: Use Drizzle ORM for type-safe queries, Neon serverless Postgres for edge-compatible connections. Schema-first design with automatic TypeScript types. Use RQB v2 with
defineRelations()and object-basedwheresyntax. Relational queries with.with()avoid N+1 problems. Use transactions for atomic operations.
<critical_requirements>
All code must follow project conventions in CLAUDE.md (kebab-case, named exports, import ordering,
import type, named constants)
(You MUST set casing: 'snake_case' in Drizzle config to map camelCase JS to snake_case SQL)
(You MUST use tx parameter (NOT db) inside transaction callbacks to ensure atomicity)
(You MUST use .with() for relational queries to avoid N+1 problems - fetches all data in single SQL query)
(You MUST use defineRelations() for RQB v2 - the old relations() per-table syntax is deprecated)
</critical_requirements>
Detailed Resources:
Auto-detection: drizzle-orm, @neondatabase/serverless, neon-http, db.query, db.transaction, drizzle-kit, pgTable, defineRelations, drizzle-seed
When to use:
When NOT to use:
Key patterns covered:
defineRelations() and object-based syntax (NEW).with() (single SQL query).through() (eliminates junction table boilerplate)Drizzle ORM provides SQL-like queries with TypeScript safety and zero runtime overhead. Neon Serverless offers PostgreSQL over HTTP/WebSocket for edge compatibility.
When to use this stack:
When NOT to use:
Configure Drizzle with Neon for serverless/edge compatibility.
// Good Example - Proper Neon HTTP setup
import { neon } from "@neondatabase/serverless";
import { drizzle } from "drizzle-orm/neon-http";
import * as schema from "./db/schema";
if (!process.env.DATABASE_URL) {
throw new Error("DATABASE_URL environment variable is not set");
}
// Use neon() for HTTP-based queries (edge-compatible)
export const sql = neon(process.env.DATABASE_URL);
// Initialize Drizzle with schema and snake_case mapping
export const db = drizzle(sql, {
schema,
casing: "snake_case", // Maps camelCase JS to snake_case SQL
});
// Export tables for direct query access
export const { jobs, companies, companyLocations, skills, jobSkills } = schema;
Why good: Environment variable validation prevents runtime errors, casing: "snake_case" ensures JS camelCase maps correctly to SQL snake_case preventing field name mismatches, HTTP connection works in all serverless environments
// drizzle.config.ts
import { defineConfig } from "drizzle-kit";
export default defineConfig({
schema: "./lib/db/schema.ts",
out: "./drizzle", // Migration files output
dialect: "postgresql",
dbCredentials: {
url: process.env.DATABASE_URL!,
},
});
For more connection examples (WebSocket, error handling), see examples/core.md.
Define tables with TypeScript types using Drizzle's schema builder.
import {
pgTable,
uuid,
varchar,
text,
timestamp,
boolean,
integer,
pgEnum,
} from "drizzle-orm/pg-core";
// Define enums for constrained values
export const employmentTypeEnum = pgEnum("employment_type", [
"full_time",
"part_time",
"contract",
"internship",
"freelance",
]);
export const seniorityLevelEnum = pgEnum("seniority_level", [
"intern",
"junior",
"mid",
"senior",
"lead",
"principal",
]);
// Good Example - Well-structured table with constraints
export const companies = pgTable("companies", {
id: uuid("id").primaryKey().defaultRandom(),
name: varchar("name", { length: 255 }).notNull(),
slug: varchar("slug", { length: 255 }).unique(),
description: text("description"),
logoUrl: text("logo_url"),
websiteUrl: text("website_url"),
createdAt: timestamp("created_at").defaultNow(),
updatedAt: timestamp("updated_at").defaultNow(),
deletedAt: timestamp("deleted_at"), // Soft delete
});
Why good: uuid().defaultRandom() generates secure unique IDs, .notNull() enforces required fields preventing null errors, enums constrain values to valid options, deletedAt enables soft deletes preserving data history, createdAt/updatedAt track record lifecycle
For complete schema examples (relations, junction tables), see examples/core.md.
.with()Fetch related data efficiently in a single SQL query.
// Good Example - Efficient relational query
import { and, eq, desc, asc, isNull } from "drizzle-orm";
const job = await db.query.jobs.findFirst({
where: and(
eq(jobs.id, jobId),
eq(jobs.isActive, true),
isNull(jobs.deletedAt),
),
with: {
company: {
with: {
locations: {
orderBy: [
desc(companyLocations.isHeadquarters),
asc(companyLocations.name),
],
},
},
},
jobSkills: {
where: eq(jobSkills.isRequired, true),
with: {
skill: true,
},
},
},
});
// Result is fully typed and nested
if (job) {
console.log(job.title); // string
console.log(job.company.name); // string
console.log(job.company.locations); // CompanyLocation[]
console.log(job.jobSkills[0].skill.name); // string
}
Why good: Single SQL query eliminates N+1 problem, nested .with() loads deep relations efficiently, soft delete check prevents returning deleted records, ordering nested results provides predictable output, fully typed results catch errors at compile time
When to use: Need related data across tables, want to avoid N+1 queries, prefer type-safe queries over raw SQL
When not to use: Simple queries without relations (use db.select()), need custom JOINs with complex conditions (use query builder)
For more query examples (N+1 anti-pattern, complex filtering), see examples/queries.md.
The following patterns are documented with full examples in examples/:
generate vs push - see migrations.mdPerformance optimization (indexes, prepared statements, pagination) is documented in reference.md.
<red_flags>
db instead of tx inside transactions - Bypasses transaction context, breaking atomicity.with() to fetch in one querycasing: 'snake_case' - Field name mismatches between JS and SQLrelations() per-table syntax - Deprecated, use defineRelations()where/orderBy - v1 syntax deprecated, use object-based syntaxisNull(deletedAt))Gotchas & Edge Cases:
enableRLS() deprecated in v1.0.0-beta.1 - use pgTable.withRLS() insteaddrizzle-zod is now drizzle-orm/zodFor the complete list of anti-patterns and gotchas, see reference.md.
</red_flags>
<critical_reminders>
All code must follow project conventions in CLAUDE.md
(You MUST set casing: 'snake_case' in Drizzle config to map camelCase JS to snake_case SQL)
(You MUST use tx parameter (NOT db) inside transaction callbacks to ensure atomicity)
(You MUST use .with() for relational queries to avoid N+1 problems - fetches all data in single SQL query)
(You MUST use defineRelations() for RQB v2 - the old relations() per-table syntax is deprecated)
Failure to follow these rules will cause field name mismatches, break transaction atomicity, create N+1 performance issues, and use deprecated APIs.
</critical_reminders>