Confused by the upsert
.
#111
-
Hey! I'm really confused by Also, the syntax for arguments is a bit confusing, too. Let's look at the example provided in docs: let post: post::Data = client
.post()
.upsert( // First argument is a unique filter
post::id::equals("upsert".to_string()),
( // Second argument is a tuple with the same values
// as an equivalent call to create()
true,
"title".to_string(),
"upsert".to_string(),
vec![]
),
vec![ // Final argument is a vec of updates
post::content::set(Some("new content".to_string())),
post::views::increment(1)
]
)
.exec()
.await
.unwrap(); I have two questions:
let post: post::Data = client
.post()
.upsert( // First argument is a unique filter
post::id::equals("upsert".to_string()),
( // Second argument is a tuple with the same values
// as an equivalent call to create()
true,
"title".to_string(),
"upsert".to_string(),
vec![
post::content::set(Some("new content".to_string())),
]
),
vec![ // Final argument is a vec of updates
post::views::increment(1)
]
)
.exec()
.await
.unwrap();
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
While admittedly the example in the docs may not be the easiest to understand, the structure is correct. To address your points individually:
|
Beta Was this translation helpful? Give feedback.
While admittedly the example in the docs may not be the easiest to understand, the structure is correct. To address your points individually:
content
in the create section is already specified as"upsert".to_string()
. The example is meant to demonstrate assigning different values depending on whether the record exists or not.upsert(where, create, update)
.where
is the same argument…