// Update all records in a table letpeople: Vec<Person> =db .update("person") .content(Company{ company: "SurrealDB".into(), }) .await?; dbg!(people); Ok(()) }
Translated query
This function will run the following query in the database:
UPDATE$resourceCONTENT$data;
.update().merge()
Modifies all records in a table, or a specific record, in the database.
Method Syntax
db.update(resource).merge(data)
Note
This function merges the current document / record data with the specified data.
Arguments
Argument
Description
resource
The table name or the specific record ID to create.
db.query("CREATE person:tobie SET name = 'Tobie'; CREATE person:jaime SET name = 'jaime';") .await?;
// Update all records in a table letpeople: Vec<Person> =db .update("person") .merge(Company{ company: "SurrealDB".into(), }) .await?; dbg!(people);
// Update a single record letperson: Option<Person> =db .update(("person","jaime")) .merge(Settings{ active: true, marketing: true, }) .await?; dbg!(person); Ok(()) }
Translated query
This function will run the following query in the database:
UPDATE$resourceMERGE$data;
.update().patch()
Applies JSON Patch changes to all records, or a specific record, in the database.
Method Syntax
db.update(resource).patch(patch_op)
Note
This function patches the current document / record data with the specified JSON Patch data.
Arguments
Argument
Description
resource
The table name or the specific record ID to modify.
data
The JSON Patch data with which to modify the records.
Example usage
The .patch() method uses a struct called a PatchOp that contains the four methods add(), change(), remove(), and replace(). Each of these methods takes different arguments depending on the operation. For example, PathOp::remove() only takes a single argument (a path), while PathOp::replace() takes a second value for the replacement value.
db.query( " CREATE person:tobie SET name = 'Tobie', company = 'SurrealDB'; CREATE person:jaime SET name = 'jaime', company = 'SurrealDB';", ) .await?;
// Update all records in a table letpeople: Vec<Person> =db .update("person") .patch(PatchOp::replace("/created_at",Datetime::default())) .await?; dbg!(people);
// Update a record with a specific ID letperson: Option<Person> =db .update(("person","tobie")) .patch(PatchOp::replace("/settings/active",false)) .patch(PatchOp::add("/tags",["developer","engineer"])) .patch(PatchOp::remove("/company")) .await?; dbg!(person); Ok(()) }
Translated query
This function will run the following query in the database:
// Update all records in a table letpeople: Vec<Person> =db .update("person") .content(Company{ company: "SurrealDB".into(), }) .await?; dbg!(people); Ok(()) }
Translated query
This function will run the following query in the database:
UPDATE$resourceCONTENT$data;
.update().merge()
Modifies all records in a table, or a specific record, in the database.
Method Syntax
db.update(resource).merge(data)
Note
This function merges the current document / record data with the specified data.
Arguments
Argument
Description
resource
The table name or the specific record ID to create.
db.query("CREATE person:tobie SET name = 'Tobie'; CREATE person:jaime SET name = 'jaime';") .await?;
// Update all records in a table letpeople: Vec<Person> =db .update("person") .merge(Company{ company: "SurrealDB".into(), }) .await?; dbg!(people);
// Update a single record letperson: Option<Person> =db .update(("person","jaime")) .merge(Settings{ active: true, marketing: true, }) .await?; dbg!(person); Ok(()) }
Translated query
This function will run the following query in the database:
UPDATE$resourceMERGE$data;
.update().patch()
Applies JSON Patch changes to all records, or a specific record, in the database.
Method Syntax
db.update(resource).patch(patch_op)
Note
This function patches the current document / record data with the specified JSON Patch data.
Arguments
Argument
Description
resource
The table name or the specific record ID to modify.
data
The JSON Patch data with which to modify the records.
Example usage
The .patch() method uses a struct called a PatchOp that contains the four methods add(), change(), remove(), and replace(). Each of these methods takes different arguments depending on the operation. For example, PathOp::remove() only takes a single argument (a path), while PathOp::replace() takes a second value for the replacement value.
db.query( " CREATE person:tobie SET name = 'Tobie', company = 'SurrealDB'; CREATE person:jaime SET name = 'jaime', company = 'SurrealDB';", ) .await?;
// Update all records in a table letpeople: Vec<Person> =db .update("person") .patch(PatchOp::replace("/created_at",Datetime::default())) .await?; dbg!(people);
// Update a record with a specific ID letperson: Option<Person> =db .update(("person","tobie")) .patch(PatchOp::replace("/settings/active",false)) .patch(PatchOp::add("/tags",&["developer","engineer"])) .patch(PatchOp::remove("/company")) .await?; dbg!(person); Ok(()) }
Translated query
This function will run the following query in the database: