mirror of
https://github.com/chatmail/core.git
synced 2026-05-20 15:26:30 +03:00
Pass mutable Connection reference to with_conn callback
This makes it possible to call .transaction() method on connection.
This commit is contained in:
@@ -115,11 +115,11 @@ impl Sql {
|
|||||||
|
|
||||||
fn with_conn<T, G>(&self, g: G) -> Result<T>
|
fn with_conn<T, G>(&self, g: G) -> Result<T>
|
||||||
where
|
where
|
||||||
G: FnOnce(&Connection) -> Result<T>,
|
G: FnOnce(&mut Connection) -> Result<T>,
|
||||||
{
|
{
|
||||||
let res = match &*self.pool.read().unwrap() {
|
let res = match &*self.pool.read().unwrap() {
|
||||||
Some(pool) => {
|
Some(pool) => {
|
||||||
let conn = pool.get()?;
|
let mut conn = pool.get()?;
|
||||||
|
|
||||||
// Only one process can make changes to the database at one time.
|
// Only one process can make changes to the database at one time.
|
||||||
// busy_timeout defines, that if a second process wants write access,
|
// busy_timeout defines, that if a second process wants write access,
|
||||||
@@ -130,7 +130,7 @@ impl Sql {
|
|||||||
// (without a busy_timeout, sqlite3_step() would return SQLITE_BUSY _at once_)
|
// (without a busy_timeout, sqlite3_step() would return SQLITE_BUSY _at once_)
|
||||||
conn.busy_timeout(Duration::from_secs(10))?;
|
conn.busy_timeout(Duration::from_secs(10))?;
|
||||||
|
|
||||||
g(&conn)
|
g(&mut conn)
|
||||||
}
|
}
|
||||||
None => Err(Error::SqlNoConnection),
|
None => Err(Error::SqlNoConnection),
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user