// upsert one record in a table letperson: Option<Person> =db .upsert(("person","jaime")) .content(Company{ company: "SurrealDB".into(), }) .await?; dbg!(person); Ok(()) }
Translated query
This function will run the following query in the database:
upsert$resourceCONTENT$data;
.upsert().merge()
Modifies all records in a table, or a specific record, in the database.
Method Syntax
db.upsert(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.
// upsert a single record letperson: Option<Person> =db .upsert(("person","tobie")) .merge(Person{ name: "Tobie".into(), ..Default::default() }) .await?;
dbg!(person); Ok(()) }
Translated query
This function will run the following query in the database:
upsert$resourceMERGE$data;
.upsert().patch()
Applies JSON Patch changes to all records, or a specific record, in the database.
Method Syntax
db.upsert(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.
// upsert a record with a specific ID letperson: Option<Person> =db .upsert(("person","tobie")) .patch(PatchOp::replace("/name","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:
// upsert one record in a table letperson: Option<Person> =db .upsert(("person","jaime")) .content(Company{ company: "SurrealDB".into(), }) .await?; dbg!(person); Ok(()) }
Translated query
This function will run the following query in the database:
upsert$resourceCONTENT$data;
.upsert().merge()
Modifies all records in a table, or a specific record, in the database.
Method Syntax
db.upsert(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.
// upsert a single record letperson: Option<Person> =db .upsert(("person","tobie")) .merge(Person{ name: "Tobie".into(), ..Default::default() }) .await?;
dbg!(person); Ok(()) }
Translated query
This function will run the following query in the database:
upsert$resourceMERGE$data;
.upsert().patch()
Applies JSON Patch changes to all records, or a specific record, in the database.
Method Syntax
db.upsert(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.
// upsert a record with a specific ID letperson: Option<Person> =db .upsert(("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: