Skip to content
🚀 This documentation is for unreal-orm 1.0.0 alpha which requires SurrealDB 2.0 SDK. For use with version 1.x, see here.

Deleting Records

Models expose both instance and static delete methods, plus a deleteMany helper.

await User.delete(db, userId);
const user = await User.create(db, { ... });
await user.delete(db);
await User.delete(db, {
where: (f) => f.inactive.isTrue(),
});
await User.deleteMany(db, {
where: (f) => f.createdAt.lt(surql`time::now() - 1y`),
});

The ORM does not enforce soft deletes. Implement them with a flag and a static helper:

class Post extends Table.normal({
name: 'post',
fields: {
isDeleted: Field.bool({ default: surql`false` }),
},
}) {
static async allActive(db) {
return this.select(db, { where: (f) => f.isDeleted.isFalse() });
}
}