From aai-stack-prisma
Provides Prisma Client query patterns for CRUD operations, relations, filtering with comparison/string/logical operators, and bulk actions. Useful for TypeScript database queries.
How this skill is triggered — by the user, by Claude, or both
Slash command
/aai-stack-prisma:prisma-queriesThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Patterns for querying data with Prisma Client.
Patterns for querying data with Prisma Client.
// 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,
})
// 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 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 by ID
const user = await prisma.user.delete({
where: { id: userId },
})
// Delete many
const result = await prisma.user.deleteMany({
where: { role: 'INACTIVE' },
})
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] },
},
})
const users = await prisma.user.findMany({
where: {
name: { contains: 'john' },
name: { startsWith: 'J' },
name: { endsWith: 'Doe' },
email: { mode: 'insensitive' }, // Case-insensitive
},
})
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' },
},
})
// 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 },
},
},
})
// 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 specific fields
const user = await prisma.user.findUnique({
where: { id: userId },
select: {
id: true,
email: true,
posts: {
select: {
id: true,
title: true,
},
},
},
})
const users = await prisma.user.findMany({
include: {
_count: {
select: {
posts: true,
followers: true,
},
},
},
})
const count = await prisma.user.count({
where: { role: 'USER' },
})
const result = await prisma.order.aggregate({
_count: { _all: true },
_sum: { total: true },
_avg: { total: true },
_min: { total: true },
_max: { total: true },
where: { status: 'COMPLETED' },
})
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 } },
},
})
// 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 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}
`
Used by:
database-developer agentfullstack-developer agentnpx claudepluginhub bradtaylorsf/alphaagent-teamSearches MemPalace before answering questions about past work, people, projects, or prior decisions. Returns verbatim stored content instead of guessing from model memory.
Guides Payload CMS config (payload.config.ts), collections, fields, hooks, access control, APIs. Debugs validation errors, security, relationships, queries, transactions, hook behavior.
Implements vector databases with Pinecone, Weaviate, Qdrant, Milvus, pgvector for semantic search, RAG, recommendations, and similarity systems. Optimizes embeddings, indexing, and hybrid search.