mirror of
https://github.com/chatmail/core.git
synced 2026-05-16 21:36:30 +03:00
refactor: directly use connectives (#6128)
Just a small refactoring. Instead of rebinding res all the time just use `and` and `and_then`how they are inteded to be used. Improves code readability imo.
This commit is contained in:
21
src/sql.rs
21
src/sql.rs
@@ -154,29 +154,28 @@ impl Sql {
|
|||||||
// don't have main database passphrase at this point.
|
// don't have main database passphrase at this point.
|
||||||
// See <https://sqlite.org/c3ref/c_dbconfig_enable_fkey.html> for documentation.
|
// See <https://sqlite.org/c3ref/c_dbconfig_enable_fkey.html> for documentation.
|
||||||
// Without resetting import may fail due to existing tables.
|
// Without resetting import may fail due to existing tables.
|
||||||
let res = res.and_then(|_| {
|
res.and_then(|_| {
|
||||||
conn.set_db_config(DbConfig::SQLITE_DBCONFIG_RESET_DATABASE, true)
|
conn.set_db_config(DbConfig::SQLITE_DBCONFIG_RESET_DATABASE, true)
|
||||||
.context("failed to set SQLITE_DBCONFIG_RESET_DATABASE")
|
.context("failed to set SQLITE_DBCONFIG_RESET_DATABASE")
|
||||||
});
|
})
|
||||||
let res = res.and_then(|_| {
|
.and_then(|_| {
|
||||||
conn.execute("VACUUM", [])
|
conn.execute("VACUUM", [])
|
||||||
.context("failed to vacuum the database")
|
.context("failed to vacuum the database")
|
||||||
});
|
})
|
||||||
let res = res.and(
|
.and(
|
||||||
conn.set_db_config(DbConfig::SQLITE_DBCONFIG_RESET_DATABASE, false)
|
conn.set_db_config(DbConfig::SQLITE_DBCONFIG_RESET_DATABASE, false)
|
||||||
.context("failed to unset SQLITE_DBCONFIG_RESET_DATABASE"),
|
.context("failed to unset SQLITE_DBCONFIG_RESET_DATABASE"),
|
||||||
);
|
)
|
||||||
let res = res.and_then(|_| {
|
.and_then(|_| {
|
||||||
conn.query_row("SELECT sqlcipher_export('main', 'backup')", [], |_row| {
|
conn.query_row("SELECT sqlcipher_export('main', 'backup')", [], |_row| {
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
.context("failed to import from attached backup database")
|
.context("failed to import from attached backup database")
|
||||||
});
|
})
|
||||||
let res = res.and(
|
.and(
|
||||||
conn.execute("DETACH DATABASE backup", [])
|
conn.execute("DETACH DATABASE backup", [])
|
||||||
.context("failed to detach backup database"),
|
.context("failed to detach backup database"),
|
||||||
);
|
)?;
|
||||||
res?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
|
|||||||
Reference in New Issue
Block a user