スキル一覧に戻る
doanchienthangdev

developing-with-prisma

by doanchienthangdev

Omega Vibecode Kit

2🍴 1📅 2026年1月21日
GitHubで見るManusで実行

SKILL.md


name: Developing with Prisma description: The agent implements Prisma ORM for type-safe database access with schema design, migrations, and queries. Use when building database layers, designing relational schemas, implementing type-safe queries, or managing database migrations.

Developing with Prisma

Quick Start

// prisma/schema.prisma
generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

model User {
  id        String   @id @default(cuid())
  email     String   @unique
  posts     Post[]
  createdAt DateTime @default(now())
  @@index([email])
}

model Post {
  id       String @id @default(cuid())
  title    String
  authorId String
  author   User   @relation(fields: [authorId], references: [id])
}
npx prisma migrate dev --name init
npx prisma generate

Features

FeatureDescriptionGuide
Schema DesignDeclarative data modeling with relationsDefine models, relations, indexes in schema.prisma
Type-Safe QueriesAuto-generated TypeScript typesUse findMany, findUnique, create, update
MigrationsVersion-controlled schema changesprisma migrate dev for development, deploy for production
RelationsOne-to-one, one-to-many, many-to-manyUse include or select to load related data
TransactionsACID operations across multiple queriesUse $transaction for atomic operations
Raw QueriesExecute raw SQL when neededUse $queryRaw for complex queries

Common Patterns

Repository with Pagination

async function findUsers(page = 1, limit = 20, where?: Prisma.UserWhereInput) {
  const [data, total] = await prisma.$transaction([
    prisma.user.findMany({ where, skip: (page - 1) * limit, take: limit, include: { profile: true } }),
    prisma.user.count({ where }),
  ]);
  return { data, pagination: { page, limit, total, totalPages: Math.ceil(total / limit) } };
}

Interactive Transaction

async function createOrder(userId: string, items: { productId: string; qty: number }[]) {
  return prisma.$transaction(async (tx) => {
    let total = 0;
    for (const item of items) {
      const product = await tx.product.update({
        where: { id: item.productId },
        data: { stock: { decrement: item.qty } },
      });
      if (product.stock < 0) throw new Error(`Insufficient stock: ${product.name}`);
      total += product.price * item.qty;
    }
    return tx.order.create({ data: { userId, total, items: { create: items } } });
  });
}

Cursor-Based Pagination

async function getPaginatedPosts(cursor?: string, take = 20) {
  const posts = await prisma.post.findMany({
    take: take + 1,
    ...(cursor && { skip: 1, cursor: { id: cursor } }),
    orderBy: { createdAt: 'desc' },
  });
  const hasMore = posts.length > take;
  return { data: hasMore ? posts.slice(0, -1) : posts, nextCursor: hasMore ? posts[take - 1].id : null };
}

Best Practices

DoAvoid
Use select to fetch only needed fieldsExposing Prisma Client directly in APIs
Create indexes for frequently queried fieldsSkipping migrations in production
Use transactions for multi-table operationsIgnoring N+1 query problems
Run migrations in CI/CD pipelinesHardcoding connection strings
Use connection pooling in productionUsing raw queries unless necessary
Validate input before database operationsUsing implicit many-to-many for complex joins
Seed development databases consistentlyIgnoring transaction isolation levels

スコア

総合スコア

60/100

リポジトリの品質指標に基づく評価

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

+10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

3ヶ月以内に更新がある

0/10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

0/5

レビュー

💬

レビュー機能は近日公開予定です