All skills
prisma avatar

/prisma-client-api

@808913c official
by prismaprisma/skills68 stars
7

Prisma Client API reference covering model queries, filters, operators, and client methods. Use when writing database queries, using CRUD operations, filtering data, or configuring Prisma Client. Triggers on "prisma query", "findMany", "create", "update", "delete", "$transaction".

Use this Skill: https://skilld.dev/gh/prisma/skills/prisma-client-api

This session only. Nothing lands on disk.

referencesmodel-queries.md

≈1.2k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Model Queries

CRUD operations for your Prisma models.

Read Operations

findUnique

Find a single record by unique field:

const user = await prisma.user.findUnique({
  where: { id: 1 }
})

const user = await prisma.user.findUnique({
  where: { email: 'alice@prisma.io' }
})
With composite unique key
// Model with @@unique([firstName, lastName])
const user = await prisma.user.findUnique({
  where: {
    firstName_lastName: {
      firstName: 'Alice',
      lastName: 'Smith'
    }
  }
})

findUniqueOrThrow

Same as findUnique but throws if not found:

const user = await prisma.user.findUniqueOrThrow({
  where: { id: 1 }
})
// Throws PrismaClientKnownRequestError if not found

findFirst

Find first matching record:

const user = await prisma.user.findFirst({
  where: { role: 'ADMIN' },
  orderBy: { createdAt: 'desc' }
})

findFirstOrThrow

const user = await prisma.user.findFirstOrThrow({
  where: { role: 'ADMIN' }
})

findMany

Find multiple records:

const users = await prisma.user.findMany({
  where: { role: 'USER' },
  orderBy: { name: 'asc' },
  take: 10,
  skip: 0
})

Create Operations

create

Create a single record:

const user = await prisma.user.create({
  data: {
    email: 'alice@prisma.io',
    name: 'Alice'
  }
})
With relations
const user = await prisma.user.create({
  data: {
    email: 'alice@prisma.io',
    posts: {
      create: [
        { title: 'First Post' },
        { title: 'Second Post' }
      ]
    }
  },
  include: { posts: true }
})

createMany

Create multiple records:

const result = await prisma.user.createMany({
  data: [
    { email: 'alice@prisma.io', name: 'Alice' },
    { email: 'bob@prisma.io', name: 'Bob' }
  ],
  skipDuplicates: true  // Skip records with duplicate unique fields
})
// Returns { count: 2 }

createManyAndReturn

Create multiple and return them:

const users = await prisma.user.createManyAndReturn({
  data: [
    { email: 'alice@prisma.io', name: 'Alice' },
    { email: 'bob@prisma.io', name: 'Bob' }
  ]
})
// Returns array of created users

Update Operations

update

Update a single record:

const user = await prisma.user.update({
  where: { id: 1 },
  data: { name: 'Alice Smith' }
})
Atomic operations
const post = await prisma.post.update({
  where: { id: 1 },
  data: {
    views: { increment: 1 },
    likes: { decrement: 1 },
    score: { multiply: 2 },
    rating: { divide: 2 },
    version: { set: 5 }
  }
})

updateMany

Update multiple records:

const result = await prisma.user.updateMany({
  where: { role: 'USER' },
  data: { verified: true }
})
// Returns { count: 42 }

updateManyAndReturn

const users = await prisma.user.updateManyAndReturn({
  where: { role: 'USER' },
  data: { verified: true }
})
// Returns array of updated users

upsert

Update or create:

const user = await prisma.user.upsert({
  where: { email: 'alice@prisma.io' },
  update: { name: 'Alice Smith' },
  create: { email: 'alice@prisma.io', name: 'Alice' }
})

Delete Operations

delete

Delete a single record:

const user = await prisma.user.delete({
  where: { id: 1 }
})
// Returns deleted record

deleteMany

Delete multiple records:

const result = await prisma.user.deleteMany({
  where: { role: 'GUEST' }
})
// Returns { count: 5 }

// Delete all
const result = await prisma.user.deleteMany({})

Aggregation Operations

count

const count = await prisma.user.count({
  where: { role: 'ADMIN' }
})

aggregate

const result = await prisma.post.aggregate({
  _avg: { views: true },
  _sum: { views: true },
  _min: { views: true },
  _max: { views: true },
  _count: { _all: true }
})

groupBy

const groups = await prisma.user.groupBy({
  by: ['country'],
  _count: { _all: true },
  _avg: { age: true },
  having: {
    age: { _avg: { gt: 30 } }
  }
})

Return Types

Method Returns
findUnique Record | null
findUniqueOrThrow Record (throws if not found)
findFirst Record | null
findFirstOrThrow Record (throws if not found)
findMany Record[]
create Record
createMany { count: number }
createManyAndReturn Record[]
update Record
updateMany { count: number }
delete Record
deleteMany { count: number }
count number
aggregate Aggregate result
groupBy Group result[]

Source: SKILL.md on GitHub

No alerts16d5 checks · Risk SAFE
  • Gen Agent Trust Hub16d

    This skill provides a comprehensive API reference for Prisma Client, covering CRUD operations, filtering, relations, and transactions. It includes documentation for raw SQL execution with explicit security warnings and best practices for preventing SQL injection. All external resources and packages are official components of the Prisma ecosystem.

  • Socket16d

    No alerts

  • Snyk16d

    Risk: LOW · No issues

  • Runlayer7mo

    9 files scanned · No issues

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 808913c. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 30 minutes ago.

Activeupdated 2 months ago
metadata
{
  "author": "prisma",
  "version": "7.9.1"
}

README badge

README badge for prisma/skills/prisma-client-api

Provides API reference for Prisma Client CRUD operations, filtering, relations, transactions, and client configuration. Use when writing database queries, performing create/read/update/delete operations, or configuring PrismaClient instantiation.

Generated from the current SKILL.md.

Does this skill cover Prisma's generated client types and TypeScript support?
The skill focuses on Prisma Client API reference and query patterns. TypeScript support is implicit in the examples, but the skill does not provide dedicated guidance on type safety, generated types, or satisfies patterns beyond mentioning them in the client-methods category.
What versions of Prisma does this skill support?
The skill is versioned 7.6.0 and targets current Prisma projects. It assumes you are using a recent Prisma Client release with adapters and extensions support.
Does this cover schema definition or migrations?
No. This skill covers only Prisma Client runtime queries and operations. Schema definition, migrations, and introspection are outside its scope.
Can I use this skill for raw SQL queries?
Yes. The skill includes a raw-queries category covering $queryRaw and $executeRaw, with guidance on safety patterns for executing raw SQL directly.
Does this skill explain how to set up Prisma Client with different databases?
The skill covers client construction and adapter wiring (e.g. PrismaPg), but database-specific setup and configuration details are deferred to the constructor reference file.

Generated from the current SKILL.md. These answers refresh after source changes.