db-operations
PostgreSQL database operations specialist using Drizzle ORM for schema management, queries, and migrations
Installation
Suivez les instructions du dépôt pour votre agent. Consultez les fichiers et dépendances avant l’installation.
Voir la source ↗GuidesInstructions
Database Operations Specialist
Instructions
When working with PostgreSQL and Drizzle ORM:
-
Schema Management
- Define tables in
src/db/schema.ts - Use
npm run db:generateto create migrations - Apply migrations with
npm run db:migrate - Use
npm run db:pushfor quick schema updates
- Define tables in
-
Database Queries
- Import
dbfromsrc/db - Use Drizzle's select() with table references
- Implement proper joins for related data
- Add indexes for performance optimization
- Import
-
User Preferences
- Use
user_preferencestable for liked content - Use
user_dislikesfor content to exclude - Use
user_peoplefor favorite actors/directors - Always include user ID in queries
- Use
-
Performance
- Add indexes on frequently queried columns
- Use
explain()to analyze query performance - Implement pagination for large result sets
- Consider caching for frequently accessed data
Examples
Creating a new table:
import { pgTable, serial, text, timestamp } from 'drizzle-orm/pg-core'
export const newTable = pgTable('new_table', {
id: serial('id').primaryKey(),
name: text('name').notNull(),
createdAt: timestamp('created_at').defaultNow(),
})
Querying user preferences:
import { db, userPreferences } from '@/db'
import { eq } from 'drizzle-orm'
const preferences = await db.select()
.from(userPreferences)
.where(eq(userPreferences.userId, userId))
Running migration:
npm run db:generate # Generate migration file
npm run db:migrate # Apply migration
npm run db:studio # Open Drizzle Studio
Exemples
Consultez les exemples du dépôt source.
Voir la source ↗Historique source
- Date d’indexation
- 2026-01-20
- Mise à jour de l’index
- 2026-01-26
- Branch
- main
Les dates concernent ce répertoire. Consultez le dépôt pour l’historique du code.
GitHub ↗chat Comments (0)
Sign in to join the discussion and leave a comment.
No comments yet. Be the first to share your thoughts!