Skip to main content 홈 크리에이터 kevinreber pixel-studio database-operation
database-operation Write Prisma database queries and server functions. Use when creating database operations, queries, migrations, or when the user mentions database, Prisma, query, model, or schema.
설치로 이동 Skills Marketplace 커뮤니티가 만든 AI 스킬을 발견하고 탐색하세요.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
직접 명령은 검토 Prompt를 거치지 않습니다. 실행하기 전에 소스를 확인하세요.
npx skills add https://github.com/kevinreber/pixel-studio --skill database-operation명령은 한 줄로 유지됩니다. 복사하기 전에 가로로 스크롤해 전체 내용을 확인하세요.
로컬 사본을 원하시나요? SkillsMP에서 현재 제공할 수 있는 파일을 다운로드하세요.
Zip 다운로드 다운로드 중... name database-operation description Write Prisma database queries and server functions. Use when creating database operations, queries, migrations, or when the user mentions database, Prisma, query, model, or schema. allowed-tools ["Read","Write","Edit","Glob","Grep","Bash"]
Database Operations with Prisma
Create database operations following Pixel Studio's established patterns.
Prisma Client Import
Always use the singleton client:
import { prisma } from "~/services/prisma.server" ;
Never create a new PrismaClient instance directly.
Server Function Structure
Server functions go in app/server/ with .server.ts suffix:
import { prisma } from "~/services/prisma.server" ;
export interface GetResourceResponse {
resources : Resource [];
total : number ;
}
export async function getResources ( ): < > {
[resources, total] = . ([
prisma. . ({
: { userId },
: (page - ) * pageSize,
: pageSize,
: { : },
}),
prisma. . ({ : { userId } }),
]);
{ resources, total };
}
userId : string ,
page = 1 ,
pageSize = 20 ,
Promise
GetResourceResponse
const
await
Promise
all
resource
findMany
where
skip
1
take
orderBy
createdAt
"desc"
resource
count
where
return
Common Query Patterns
Find with Relations const image = await prisma.image .findUnique ({
where : { id : imageId },
include : {
user : { select : { id : true , name : true , image : true } },
comments : {
orderBy : { createdAt : "desc" },
include : { user : { select : { id : true , name : true } } },
},
likes : { select : { userId : true } },
_count : { select : { comments : true , likes : true } },
},
});
Pagination const pageSize = 20 ;
const currentPage = 1 ;
const images = await prisma.image .findMany ({
skip : (currentPage - 1 ) * pageSize,
take : pageSize,
orderBy : { createdAt : "desc" },
where : { isPublic : true },
});
const total = await prisma.image .count ({ where : { isPublic : true } });
const totalPages = Math .ceil (total / pageSize);
Count Relations const collections = await prisma.collection .findMany ({
where : { userId },
select : {
id : true ,
title : true ,
_count : { select : { images : true } },
},
});
Conditional Includes const user = await prisma.user .findUnique ({
where : { id : userId },
include : {
images : imageId ? { where : { id : imageId }, select : { id : true } } : false ,
},
});
Search with OR Conditions const images = await prisma.image .findMany ({
where : {
OR : [
{ prompt : { contains : searchTerm, mode : "insensitive" } },
{ title : { contains : searchTerm, mode : "insensitive" } },
],
isPublic : true ,
},
});
Transaction for Multiple Operations const result = await prisma.$transaction(async (tx) => {
await tx.user .update ({
where : { id : userId },
data : { credits : { decrement : creditCost } },
});
const image = await tx.image .create ({
data : { userId, prompt, url },
});
return image;
});
CRUD Operations Pattern
Create export async function createCollection (
userId : string ,
data : { title: string ; description?: string },
) {
return prisma.collection .create ({
data : {
...data,
userId,
},
});
}
Read export async function getCollectionById (id : string , userId ?: string ) {
const collection = await prisma.collection .findUnique ({
where : { id },
include : {
images : { orderBy : { createdAt : "desc" } },
_count : { select : { images : true } },
},
});
if (!collection) return null ;
if (!collection.isPublic && collection.userId !== userId) return null ;
return collection;
}
Update export async function updateCollection (
id : string ,
userId : string ,
data : { title?: string ; description?: string },
) {
return prisma.collection .update ({
where : { id, userId },
data,
});
}
Delete export async function deleteCollection (id : string , userId : string ) {
await prisma.collection .update ({
where : { id, userId },
data : { images : { set : [] } },
});
return prisma.collection .delete ({
where : { id, userId },
});
}
Relationship Operations
Many-to-Many: Add/Remove
await prisma.collection .update ({
where : { id : collectionId },
data : {
images : { connect : { id : imageId } },
},
});
await prisma.collection .update ({
where : { id : collectionId },
data : {
images : { disconnect : { id : imageId } },
},
});
Toggle Operation (Like/Unlike) export async function toggleLike (imageId : string , userId : string ) {
const existing = await prisma.imageLike .findUnique ({
where : { userId_imageId : { userId, imageId } },
});
if (existing) {
await prisma.imageLike .delete ({
where : { userId_imageId : { userId, imageId } },
});
return { liked : false };
}
await prisma.imageLike .create ({
data : { userId, imageId },
});
return { liked : true };
}
Schema Reference Key models in prisma/schema.prisma:
model User {
id String @id @default(cuid())
email String @unique
name String?
image String?
credits Int @default(10)
images Image[]
collections Collection[]
followers Follow[] @relation("following")
following Follow[] @relation("follower")
}
model Image {
id String @id @default(cuid())
prompt String
url String
model String
userId String
user User @relation(fields: [userId], references: [id])
collections Collection[]
likes ImageLike[]
comments Comment[]
}
Database Commands
npx prisma studio
npx prisma db push
npx prisma generate
npx prisma migrate dev --name description
npx prisma migrate reset
Checklist