Updating Records
Updates in UnrealORM require an explicit mode so the generated SurrealQL is clear.
content — full replacement
Section titled “content — full replacement”await User.update(db, userId, { data: { name: 'New Name' }, mode: 'content',});merge — partial update
Section titled “merge — partial update”await User.update(db, userId, { data: { name: 'New Name' }, mode: 'merge',});replace — full record replacement
Section titled “replace — full record replacement”await User.update(db, userId, { data: { name: 'New Name', email: 'new@example.com' }, mode: 'replace',});set — computed expressions
Section titled “set — computed expressions”await Post.update(db, postId, { mode: 'set', data: { views: surql`views + 1`, updatedAt: new Date(), },});You can also use ColumnRef values from the field proxy.
patch — JSON Patch
Section titled “patch — JSON Patch”await User.update(db, userId, { mode: 'patch', data: [ { op: 'replace', path: '/name', value: 'New Name' }, ],});Instance update
Section titled “Instance update”Model instances also have an update method:
const user = await User.select(db, { only: true, where: (f) => f.id.eq(userId) });await user.update(db, { data: { name: 'New Name' }, mode: 'merge' });Updating many records
Section titled “Updating many records”await User.updateMany(db, { where: (f) => f.active.isFalse(), data: { active: true }, mode: 'merge',});Return values
Section titled “Return values”const updated = await User.update(db, userId, { data: { name: 'New Name' }, mode: 'merge', return: 'AFTER',});