agentleFS
G1JoshiG1Joshi/Agent-Skills/skills/frameworks/prisma/SKILL.md

prisma

Skill15 starsChanged 42 days agoMITView on GitHub

Expert Prisma ORM assistance covering Prisma schema, migrations, type-safe queries, relation filters, and Accelerate. Use when modeling databases and querying SQL in TypeScript/JavaScript.

7 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

5 rules. 0 are common, 0 are distinctive, and 5 are very specific to this project.

  • 0

    Common

    Most of the 7 edited versions we read keep these.

  • 0

    Distinctive

    This author's own choices. Worth a look.

  • 5

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Use select clauses in queries to fetch only necessary columns instead of full rows.

    line 179
  2. Very specific:

    Run prisma migrate deploy in CI/CD production deployment pipelines.

    line 180
  3. Very specific:

    Create new PrismaClient() instances inside serverless request handler functions.

    line 185
  4. Very specific:

    Run prisma db push in production.

    line 186
  5. Very specific:

    Use $queryRawUnsafe with concatenated user strings.

    line 187

“Common” is measured: kept by at least 6 in 10 of the 7 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Prisma

Prisma is a next-generation Node.js and TypeScript ORM featuring declarative schema modeling, automated type-safe database queries, and robust migration tooling.

When to Use

  • TypeScript-First Database Modeling: Declarative data models with automated migrations and end-to-end type safety.
  • Next.js & Node.js Enterprise Backends: Developing web services with Prisma Client and PostgreSQL/MySQL/SQLite/MongoDB.
  • Safe Relational Query Composition: Fluent queries with deeply nested relations, filtering, and pagination.
  • Prisma Accelerate & Pulse: Edge caching, connection pooling, and real-time database change-event subscriptions.

Quick Start

// schema.prisma
datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

generator client {
  provider = "prisma-client-js"
}

model User {
  id    Int     @id @default(autoincrement())
  email String  @unique
  name  String?
  posts Post[]
}

model Post {
  id        Int     @id @default(autoincrement())
  title     String
  authorId  Int
  author    User    @relation(fields: [authorId], references: [id])
}
import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient();

const users = await prisma.user.findMany({ include: { posts: true } });

Core Concepts

Declarative Schema Definition with Relations

Defining entities, indexes, and referential constraints:

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

generator client {
  provider = "prisma-client-js"
}

model User {
  id        Int       @id @default(autoincrement())
  email     String    @unique
  name      String?
  posts     Post[]
  createdAt DateTime  @default(now())
}

model Post {
  id        Int      @id @default(autoincrement())
  title     String
  content   String?
  published Boolean  @default(false)
  author    User     @relation(fields: [authorId], references: [id], onDelete: Cascade)
  authorId  Int

  @@index([authorId])
}

Type-Safe CRUD & Nested Relational Queries

Reading and writing related data in single operations:

import { PrismaClient } from "@prisma/client";

const prisma = new PrismaClient();

async function createUserWithPost() {
  const user = await prisma.user.create({
    data: {
      email: "alex@example.com",
      name: "Alex Rivera",
      posts: {
        create: [{ title: "Getting Started with Prisma", published: true }],
      },
    },
    include: {
      posts: true,
    },
  });

  return user;
}

Interactive Transactions with $transaction

Executing multi-step operations with ACID guarantees:

async function transferFunds(
  fromUserId: number,
  toUserId: number,
  amount: number,
) {
  return await prisma.$transaction(async (tx) => {
    const sender = await tx.account.update({
      where: { userId: fromUserId },
      data: { balance: { decrement: amount } },
    });

    if (sender.balance < 0) {
      throw new Error("Insufficient funds");
    }

    const receiver = await tx.account.update({
      where: { userId: toUserId },
      data: { balance: { increment: amount } },
    });

    return { sender, receiver };
  });
}

Common Patterns

Interactive Transactions with Rollback Safety

Problem: Updating multiple tables where failure of any step must roll back previous changes.

Solution: Use $transaction closure:

const result = await prisma.$transaction(async (tx) => {
  const sender = await tx.account.update({
    where: { id: fromAccountId },
    data: { balance: { decrement: amount } },
  });

  if (sender.balance < 0) {
    throw new Error("Insufficient funds for transfer");
  }

  const recipient = await tx.account.update({
    where: { id: toAccountId },
    data: { balance: { increment: amount } },
  });

  return { sender, recipient };
});

Best Practices

Do:

  • Instantiate a single PrismaClient instance globally in development to prevent connection pool exhaustion.
  • Use select clauses in queries to fetch only necessary columns instead of full rows.
  • Run prisma migrate deploy in CI/CD production deployment pipelines.
  • Leverage interactive transactions (prisma.$transaction(async (tx) => ...)) for ACID workflows.

Don't:

  • Create new PrismaClient() instances inside serverless request handler functions.
  • Run prisma db push in production; use prisma migrate to preserve migration history.
  • Use $queryRawUnsafe with concatenated user strings; use parameterized $queryRaw.

Troubleshooting

ErrorCauseSolution
PrismaClientInitializationError: Can't reach database serverDatabase offline, network partition, or invalid DATABASE_URL.Check database connection string and network reachability.
PrismaClientKnownRequestError: P2002 Unique constraint failedAttempting to insert a duplicate value for a @unique column.Catch code P2002 and return user-friendly duplicate error.
Prisma Client not initialized / outdated typesSchema was modified without regenerating client.Run npx prisma generate after modifying schema.prisma.

References

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.