prisma-queries
Prisma Client query patterns
What this skill does
# Prisma Queries Skill
Patterns for querying data with Prisma Client.
## Basic CRUD
### Create
```typescript
// Create single record
const user = await prisma.user.create({
data: {
email: '[email protected]',
name: 'John Doe',
},
})
// Create with relations
const user = await prisma.user.create({
data: {
email: '[email protected]',
profile: {
create: { bio: 'Hello!' },
},
posts: {
create: [
{ title: 'First Post' },
{ title: 'Second Post' },
],
},
},
include: {
profile: true,
posts: true,
},
})
// Create many
const users = await prisma.user.createMany({
data: [
{ email: '[email protected]' },
{ email: '[email protected]' },
],
skipDuplicates: true,
})
```
### Read
```typescript
// Find by ID
const user = await prisma.user.findUnique({
where: { id: userId },
})
// Find by unique field
const user = await prisma.user.findUnique({
where: { email: '[email protected]' },
})
// Find first matching
const user = await prisma.user.findFirst({
where: { role: 'ADMIN' },
})
// Find many with conditions
const users = await prisma.user.findMany({
where: {
role: 'USER',
createdAt: { gte: new Date('2024-01-01') },
},
orderBy: { createdAt: 'desc' },
take: 10,
skip: 0,
})
// Find or throw
const user = await prisma.user.findUniqueOrThrow({
where: { id: userId },
})
```
### Update
```typescript
// Update by ID
const user = await prisma.user.update({
where: { id: userId },
data: { name: 'New Name' },
})
// Update many
const result = await prisma.user.updateMany({
where: { role: 'GUEST' },
data: { role: 'USER' },
})
// Upsert (create or update)
const user = await prisma.user.upsert({
where: { email: '[email protected]' },
update: { name: 'John' },
create: { email: '[email protected]', name: 'John' },
})
```
### Delete
```typescript
// Delete by ID
const user = await prisma.user.delete({
where: { id: userId },
})
// Delete many
const result = await prisma.user.deleteMany({
where: { role: 'INACTIVE' },
})
```
## Filtering
### Comparison Operators
```typescript
const users = await prisma.user.findMany({
where: {
age: { equals: 30 },
age: { not: 30 },
age: { gt: 18 },
age: { gte: 18 },
age: { lt: 65 },
age: { lte: 65 },
age: { in: [18, 21, 30] },
age: { notIn: [0, 1] },
},
})
```
### String Filters
```typescript
const users = await prisma.user.findMany({
where: {
name: { contains: 'john' },
name: { startsWith: 'J' },
name: { endsWith: 'Doe' },
email: { mode: 'insensitive' }, // Case-insensitive
},
})
```
### Logical Operators
```typescript
const users = await prisma.user.findMany({
where: {
AND: [
{ role: 'USER' },
{ active: true },
],
},
})
const users = await prisma.user.findMany({
where: {
OR: [
{ role: 'ADMIN' },
{ role: 'MODERATOR' },
],
},
})
const users = await prisma.user.findMany({
where: {
NOT: { role: 'GUEST' },
},
})
```
### Relation Filters
```typescript
// Filter by related records
const users = await prisma.user.findMany({
where: {
posts: {
some: { published: true },
},
},
})
const users = await prisma.user.findMany({
where: {
posts: {
every: { published: true },
},
},
})
const users = await prisma.user.findMany({
where: {
posts: {
none: { published: false },
},
},
})
// Count related
const users = await prisma.user.findMany({
where: {
posts: {
some: {},
},
_count: {
posts: { gt: 5 },
},
},
})
```
## Relations
### Include
```typescript
// Include related records
const user = await prisma.user.findUnique({
where: { id: userId },
include: {
posts: true,
profile: true,
},
})
// Nested include
const user = await prisma.user.findUnique({
where: { id: userId },
include: {
posts: {
include: {
comments: true,
},
},
},
})
// Filter included relations
const user = await prisma.user.findUnique({
where: { id: userId },
include: {
posts: {
where: { published: true },
orderBy: { createdAt: 'desc' },
take: 5,
},
},
})
```
### Select
```typescript
// Select specific fields
const user = await prisma.user.findUnique({
where: { id: userId },
select: {
id: true,
email: true,
posts: {
select: {
id: true,
title: true,
},
},
},
})
```
### Relation Count
```typescript
const users = await prisma.user.findMany({
include: {
_count: {
select: {
posts: true,
followers: true,
},
},
},
})
```
## Aggregation
### Count
```typescript
const count = await prisma.user.count({
where: { role: 'USER' },
})
```
### Aggregate
```typescript
const result = await prisma.order.aggregate({
_count: { _all: true },
_sum: { total: true },
_avg: { total: true },
_min: { total: true },
_max: { total: true },
where: { status: 'COMPLETED' },
})
```
### Group By
```typescript
const result = await prisma.order.groupBy({
by: ['status'],
_count: { _all: true },
_sum: { total: true },
orderBy: {
_count: { _all: 'desc' },
},
})
// With having
const result = await prisma.order.groupBy({
by: ['userId'],
_sum: { total: true },
having: {
total: { _sum: { gt: 1000 } },
},
})
```
## Transactions
```typescript
// Interactive transaction
const result = await prisma.$transaction(async (tx) => {
const user = await tx.user.create({
data: { email: '[email protected]' },
})
await tx.profile.create({
data: { userId: user.id, bio: 'Hello' },
})
return user
})
// Batch transaction
const [user, post] = await prisma.$transaction([
prisma.user.create({ data: { email: '[email protected]' } }),
prisma.post.create({ data: { title: 'New Post', authorId: 'existing-id' } }),
])
```
## Raw Queries
```typescript
// Raw query
const users = await prisma.$queryRaw`
SELECT * FROM users WHERE role = ${role}
`
// Raw execute
await prisma.$executeRaw`
UPDATE users SET status = 'active' WHERE id = ${userId}
`
```
## Integration
Used by:
- `database-developer` agent
- `fullstack-developer` agent
Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.