mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 02:22:21 +00:00
store_sqlite: Implement put_object overwrite parameter
This commit is contained in:
@@ -275,20 +275,30 @@ impl AddressbookStore for SqliteStore {
|
||||
principal: String,
|
||||
addressbook_id: String,
|
||||
object: AddressObject,
|
||||
// TODO: implement
|
||||
overwrite: bool,
|
||||
) -> Result<(), rustical_store::Error> {
|
||||
let mut tx = self.db.begin().await.map_err(crate::Error::from)?;
|
||||
|
||||
let (object_id, vcf) = (object.get_id(), object.get_vcf());
|
||||
|
||||
sqlx::query!(
|
||||
(if overwrite {
|
||||
sqlx::query!(
|
||||
"REPLACE INTO addressobjects (principal, addressbook_id, id, vcf) VALUES (?, ?, ?, ?)",
|
||||
principal,
|
||||
addressbook_id,
|
||||
object_id,
|
||||
vcf
|
||||
)
|
||||
} else {
|
||||
// If the object already exists a database error is thrown and handled in error.rs
|
||||
sqlx::query!(
|
||||
"INSERT INTO addressobjects (principal, addressbook_id, id, vcf) VALUES (?, ?, ?, ?)",
|
||||
principal,
|
||||
addressbook_id,
|
||||
object_id,
|
||||
vcf
|
||||
)
|
||||
})
|
||||
.execute(&mut *tx)
|
||||
.await
|
||||
.map_err(crate::Error::from)?;
|
||||
|
||||
Reference in New Issue
Block a user