mirror of
https://github.com/chatmail/core.git
synced 2026-04-17 21:46:35 +03:00
Resultify sql.open()
This commit is contained in:
20
src/sql.rs
20
src/sql.rs
@@ -14,6 +14,7 @@ use crate::constants::{ShowEmails, DC_CHAT_ID_TRASH};
|
||||
use crate::context::Context;
|
||||
use crate::dc_tools::*;
|
||||
use crate::ephemeral::start_ephemeral_timers;
|
||||
use crate::error::format_err;
|
||||
use crate::param::*;
|
||||
use crate::peerstate::*;
|
||||
|
||||
@@ -78,17 +79,22 @@ impl Sql {
|
||||
}
|
||||
|
||||
// return true on success, false on failure
|
||||
pub async fn open<T: AsRef<Path>>(&self, context: &Context, dbfile: T, readonly: bool) -> bool {
|
||||
match open(context, self, dbfile, readonly).await {
|
||||
Ok(_) => true,
|
||||
Err(err) => match err.downcast_ref::<Error>() {
|
||||
Some(Error::SqlAlreadyOpen) => false,
|
||||
pub async fn open<T: AsRef<Path>>(
|
||||
&self,
|
||||
context: &Context,
|
||||
dbfile: T,
|
||||
readonly: bool,
|
||||
) -> crate::error::Result<()> {
|
||||
let res = open(context, self, dbfile, readonly).await;
|
||||
if let Err(err) = &res {
|
||||
match err.downcast_ref::<Error>() {
|
||||
Some(Error::SqlAlreadyOpen) => {}
|
||||
_ => {
|
||||
self.close().await;
|
||||
false
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
res.map_err(|e| format_err!("Could not open db: {}", e))
|
||||
}
|
||||
|
||||
pub async fn execute<S: AsRef<str>>(
|
||||
|
||||
Reference in New Issue
Block a user