database-orm
Interaction with NeonDB Postgres using Drizzle ORM.
When & Why to Use This Skill
This Claude skill enables seamless interaction with NeonDB Postgres using Drizzle ORM, providing a comprehensive framework for managing serverless database logic. It streamlines the process of initializing connections, defining type-safe schemas, and executing complex CRUD operations. By integrating Drizzle-kit for migrations, it ensures a robust and scalable workflow for modern web development, making it an essential tool for developers building data-driven applications with high performance and type safety.
Use Cases
- Case 1: Rapidly bootstrapping serverless web applications with a pre-configured NeonDB and Drizzle ORM stack to reduce setup time.
- Case 2: Automating database schema updates and version control migrations using Drizzle-kit to ensure consistency across development and production environments.
- Case 3: Implementing secure and structured data storage for AI-driven applications, such as managing chatbot conversation histories and user analysis data.
- Case 4: Developing type-safe backend services that require efficient SQL query building and execution within a TypeScript ecosystem.
| name | Database & ORM |
|---|---|
| description | Interaction with NeonDB Postgres using Drizzle ORM. |
Database Logic
Stack
- Database: Neon (Serverless Postgres)
- ORM: Drizzle ORM
- Driver:
@neondatabase/serverless
Connection
The database connection is initialized in db/index.ts.
import { neon } from '@neondatabase/serverless';
import { drizzle } from 'drizzle-orm/neon-http';
const sql = neon(process.env.DATABASE_URL!);
export const db = drizzle(sql);
Schema
Schema definitions are in db/schema.ts.
users,sessions,accounts,verifications: Auth tables.analyses,chatbot_history: App specific tables.
Operations
Example of a database query:
import { db } from "@/db";
import { users } from "@/db/schema";
import { eq } from "drizzle-orm";
// Select
const user = await db.select().from(users).where(eq(users.email, "test@example.com"));
// Insert
await db.insert(users).values({ ... });
Migrations
- Generate:
npx drizzle-kit generate - Push:
npx drizzle-kit push(or migrate script)