Skip to main content
Version: 3.0 Beta

Delete

Deleting records can be done with the following methods:

  • delete - Delete a single, unique record.
  • deleteMany - Delete multiple records that match the query criteria.
  • deleteManyAndReturn - Similar to deleteMany, but returns the deleted records

You can also delete records as part of an update operation from a relation. See Manipulating relations for details.

Samples​

Click here to open an interactive playground.
delete.ts
import { createClient } from './db';
import { createUsersAndPosts } from './utils';

async function main() {
const db = await createClient();
await createUsersAndPosts(db);

console.log('Delete a unique post');
console.log(await db.post.delete({ where: { id: 1 } } ));

console.log('Delete many posts');
console.log(await db.post.deleteMany({ where: { published: false } }));
}

main();
Comments
Feel free to ask questions, give feedback, or report issues.

Don't Spam


You can edit/delete your comments by going directly to the discussion, clicking on the 'comments' link below