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 todeleteMany, 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();