Skip to content

Latest commit

 

History

History
39 lines (29 loc) · 813 Bytes

09-delete.md

File metadata and controls

39 lines (29 loc) · 813 Bytes

Delete records

The examples use the following prisma schema:

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 a record

To delete a record, just query for a field using FindUnique or FindMany, and then just chain it by invoking .Delete().

deleted, err := client.Post.FindUnique(
    db.Post.ID.Equals("id"),
).Delete().Exec(ctx)

Next steps

Learn how to upsert documents.