删除查询
这些示例使用以下 Prisma 模式
model Post {
id String @id @default(cuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
published Boolean
title String
content String?
comments Comment[]
}
model Comment {
id String @id @default(cuid())
createdAt DateTime @default(now())
content String
post Post @relation(fields: [postID], references: [id])
postID String
}
删除
delete
将删除由单个唯一过滤器引用的记录并返回它。
以下示例查找单个帖子并将其删除,返回已删除的帖子。
use prisma::post;
let deleted_post: post::Data = client
.post()
.delete(post::id::equals("id".to_string()))
.exec()
.await?;
批量删除
delete_many
将删除由 Vec
中的所有过滤器引用的记录,并返回已删除记录的数量。
以下示例查找一组评论并将其删除,返回已删除评论的数量。
use prisma::comment;
let deleted_comments_count: i64 = client
.comment()
.delete_many(vec![
comment::content::contains("some text".to_string())
])
.exec()
.await;