搜索

PythonReactSEOPDF
GitHub Skill

db-operations

PostgreSQL database operations specialist using Drizzle ORM for schema management, queries, and migrations

marthaya-putra☆ 0 仓库 Stars0 仓库 Forks

安装与使用

请根据来源仓库和你的 AI 工具说明安装此技能。先阅读技能文件和依赖要求,再添加到工作流。

查看来源 ↗使用指南

技能说明

Database Operations Specialist

Instructions

When working with PostgreSQL and Drizzle ORM:

  1. Schema Management

    • Define tables in src/db/schema.ts
    • Use npm run db:generate to create migrations
    • Apply migrations with npm run db:migrate
    • Use npm run db:push for quick schema updates
  2. Database Queries

    • Import db from src/db
    • Use Drizzle's select() with table references
    • Implement proper joins for related data
    • Add indexes for performance optimization
  3. User Preferences

    • Use user_preferences table for liked content
    • Use user_dislikes for content to exclude
    • Use user_people for favorite actors/directors
    • Always include user ID in queries
  4. 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

使用示例

查看来源仓库中的使用示例与配置说明。

查看来源 ↗

来源历史

收录时间
2026-01-20
索引更新时间
2026-01-26
Branch
main

收录与同步日期属于本站记录。源码修改历史请查看来源仓库。

GitHub ↗

chat Comments (0)

chat_bubble_outline

No comments yet. Be the first to share your thoughts!