AiderTypeScriptDatabase

Prisma ORM Rules for Aider

Rules for using Prisma ORM effectively in TypeScript projects.

CONVENTIONS.md
# Prisma ORM Rules for Aider

# Prisma ORM Rules

## Schema Conventions
```prisma
model User {
  id        String   @id @default(cuid())
  email     String   @unique
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
  
  // Relations
  posts     Post[]
  profile   Profile? // Optional one-to-one
  
  @@index([email]) // Index on frequently queried fields
  @@map("users")   // Explicit table name — snake_case
}
```

## Client Singleton Pattern
```typescript
// lib/prisma.ts — prevents connection pool exhaustion in dev
declare global { var prisma: PrismaClient | undefined }
export const prisma = global.prisma ?? new PrismaClient({
  log: process.env.NODE_ENV === 'development' ? ['query', 'error'] : ['error'],
});
if (process.env.NODE_ENV !== 'production') global.prisma = prisma;
```

## Query Patterns
```typescript
// Select only needed fields — never select * implicitly
const user = await prisma.user.findUnique({
  where: { id },
  select: { id: true, email: true, name: true }, // Not the whole object
});

// Avoid N+1 — use include or separate queries with in

How to use with Aider

Create a `CONVENTIONS.md` file in your project root. Aider reads this and respects your conventions when generating changes.

#aider#typescript#prisma#ai-coding-rules

Related Rules