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.

referencesquery-options.md

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

Query Options

Options for controlling query behavior.

select

Choose specific fields to return:

const user = await prisma.user.findUnique({
  where: { id: 1 },
  select: {
    id: true,
    name: true,
    email: true,
    // password: false (excluded by not including)
  }
})
// Returns: { id: 1, name: 'Alice', email: 'alice@prisma.io' }

Select relations

const user = await prisma.user.findUnique({
  where: { id: 1 },
  select: {
    name: true,
    posts: {
      select: {
        title: true,
        published: true
      }
    }
  }
})

Select with include inside

const user = await prisma.user.findMany({
  select: {
    name: true,
    posts: {
      include: {
        comments: true
      }
    }
  }
})

Select relation count

const users = await prisma.user.findMany({
  select: {
    name: true,
    _count: {
      select: { posts: true }
    }
  }
})
// Returns: { name: 'Alice', _count: { posts: 5 } }

include

Include related records:

const user = await prisma.user.findUnique({
  where: { id: 1 },
  include: {
    posts: true,
    profile: true
  }
})

Filtered include

const user = await prisma.user.findUnique({
  where: { id: 1 },
  include: {
    posts: {
      where: { published: true },
      orderBy: { createdAt: 'desc' },
      take: 5
    }
  }
})

Nested include

const user = await prisma.user.findUnique({
  where: { id: 1 },
  include: {
    posts: {
      include: {
        comments: {
          include: {
            author: true
          }
        }
      }
    }
  }
})

Include relation count

const users = await prisma.user.findMany({
  include: {
    _count: {
      select: { posts: true, followers: true }
    }
  }
})

omit

Exclude specific fields:

const user = await prisma.user.findUnique({
  where: { id: 1 },
  omit: {
    password: true
  }
})
// Returns all fields except password

Omit in relations

const users = await prisma.user.findMany({
  omit: { password: true },
  include: {
    posts: {
      omit: { content: true }
    }
  }
})

Note: Cannot use select and omit together.

where

Filter records:

const users = await prisma.user.findMany({
  where: {
    email: { contains: '@prisma.io' },
    role: 'ADMIN'
  }
})

See filters.md for detailed filter operators.

orderBy

Sort results:

// Single field
const users = await prisma.user.findMany({
  orderBy: { name: 'asc' }
})

// Multiple fields
const users = await prisma.user.findMany({
  orderBy: [
    { role: 'desc' },
    { name: 'asc' }
  ]
})

Order by relation

const users = await prisma.user.findMany({
  orderBy: {
    posts: { _count: 'desc' }
  }
})

Null handling

const users = await prisma.user.findMany({
  orderBy: {
    name: { sort: 'asc', nulls: 'last' }
  }
})

take & skip

Pagination:

// First page
const users = await prisma.user.findMany({
  take: 10,
  skip: 0
})

// Second page
const users = await prisma.user.findMany({
  take: 10,
  skip: 10
})

Negative take (reverse)

const lastUsers = await prisma.user.findMany({
  take: -10,
  orderBy: { id: 'asc' }
})
// Returns last 10 users

cursor

Cursor-based pagination:

// First page
const firstPage = await prisma.user.findMany({
  take: 10,
  orderBy: { id: 'asc' }
})

// Next page using cursor
const nextPage = await prisma.user.findMany({
  take: 10,
  skip: 1,  // Skip the cursor record
  cursor: { id: firstPage[firstPage.length - 1].id },
  orderBy: { id: 'asc' }
})

distinct

Return unique values:

const cities = await prisma.user.findMany({
  distinct: ['city'],
  select: { city: true }
})

Multiple distinct fields

const locations = await prisma.user.findMany({
  distinct: ['city', 'country']
})

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.