Deleting Records
Models expose both instance and static delete methods, plus a deleteMany helper.
Delete by id
Section titled “Delete by id”await User.delete(db, userId);Instance delete
Section titled “Instance delete”const user = await User.create(db, { ... });await user.delete(db);Delete by filter
Section titled “Delete by filter”await User.delete(db, { where: (f) => f.inactive.isTrue(),});Delete many
Section titled “Delete many”await User.deleteMany(db, { where: (f) => f.createdAt.lt(surql`time::now() - 1y`),});Soft deletes
Section titled “Soft deletes”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() }); }}