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.

Updating Records

Updates in UnrealORM require an explicit mode so the generated SurrealQL is clear.

await User.update(db, userId, {
data: { name: 'New Name' },
mode: 'content',
});
await User.update(db, userId, {
data: { name: 'New Name' },
mode: 'merge',
});
await User.update(db, userId, {
data: { name: 'New Name', email: 'new@example.com' },
mode: 'replace',
});
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.

await User.update(db, userId, {
mode: 'patch',
data: [
{ op: 'replace', path: '/name', value: 'New Name' },
],
});

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' });
await User.updateMany(db, {
where: (f) => f.active.isFalse(),
data: { active: true },
mode: 'merge',
});
const updated = await User.update(db, userId, {
data: { name: 'New Name' },
mode: 'merge',
return: 'AFTER',
});