mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-02 09:35:28 +00:00
implement set_default search provider method
This commit is contained in:
parent
5347ffbbfd
commit
58d4439fcf
2 changed files with 43 additions and 4 deletions
|
|
@ -75,6 +75,25 @@ impl Database {
|
|||
Err(e) => Err(e),
|
||||
}
|
||||
}
|
||||
|
||||
/// Delete record from database
|
||||
pub fn set_default(&self, id: i64) -> Result<(), Error> {
|
||||
// Begin new transaction
|
||||
let mut writable = self.connection.write().unwrap(); // @TODO
|
||||
let tx = writable.transaction()?;
|
||||
|
||||
// Make sure only one default provider in set
|
||||
reset(&tx, *self.profile_id, false)?;
|
||||
|
||||
// Delete record by ID
|
||||
match set_default(&tx, *self.profile_id, id, true) {
|
||||
Ok(_) => match tx.commit() {
|
||||
Ok(_) => Ok(()),
|
||||
Err(e) => Err(e),
|
||||
},
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Low-level DB API
|
||||
|
|
@ -147,6 +166,18 @@ fn reset(tx: &Transaction, profile_id: i64, is_default: bool) -> Result<usize, E
|
|||
)
|
||||
}
|
||||
|
||||
fn set_default(
|
||||
tx: &Transaction,
|
||||
profile_id: i64,
|
||||
id: i64,
|
||||
is_default: bool,
|
||||
) -> Result<usize, Error> {
|
||||
tx.execute(
|
||||
"UPDATE `profile_search` SET `is_default` = ? WHERE `profile_id` = ? AND `id` = ?",
|
||||
(is_default, profile_id, id),
|
||||
)
|
||||
}
|
||||
|
||||
fn last_insert_id(tx: &Transaction) -> i64 {
|
||||
tx.last_insert_rowid()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue