mirror of
https://github.com/isar/rusqlite.git
synced 2025-04-02 04:12:59 +08:00
Allow setting default connection transaction behavior
This commit is contained in:
parent
eebbbb0086
commit
1891c39a5f
@ -377,6 +377,7 @@ impl DatabaseName<'_> {
|
|||||||
pub struct Connection {
|
pub struct Connection {
|
||||||
db: RefCell<InnerConnection>,
|
db: RefCell<InnerConnection>,
|
||||||
cache: StatementCache,
|
cache: StatementCache,
|
||||||
|
transaction_behavior: TransactionBehavior
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl Send for Connection {}
|
unsafe impl Send for Connection {}
|
||||||
@ -473,6 +474,7 @@ impl Connection {
|
|||||||
InnerConnection::open_with_flags(&c_path, flags, None).map(|db| Connection {
|
InnerConnection::open_with_flags(&c_path, flags, None).map(|db| Connection {
|
||||||
db: RefCell::new(db),
|
db: RefCell::new(db),
|
||||||
cache: StatementCache::with_capacity(STATEMENT_CACHE_DEFAULT_CAPACITY),
|
cache: StatementCache::with_capacity(STATEMENT_CACHE_DEFAULT_CAPACITY),
|
||||||
|
transaction_behavior: TransactionBehavior::Deferred
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -497,6 +499,7 @@ impl Connection {
|
|||||||
InnerConnection::open_with_flags(&c_path, flags, Some(&c_vfs)).map(|db| Connection {
|
InnerConnection::open_with_flags(&c_path, flags, Some(&c_vfs)).map(|db| Connection {
|
||||||
db: RefCell::new(db),
|
db: RefCell::new(db),
|
||||||
cache: StatementCache::with_capacity(STATEMENT_CACHE_DEFAULT_CAPACITY),
|
cache: StatementCache::with_capacity(STATEMENT_CACHE_DEFAULT_CAPACITY),
|
||||||
|
transaction_behavior: TransactionBehavior::Deferred
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -949,6 +952,7 @@ impl Connection {
|
|||||||
Ok(Connection {
|
Ok(Connection {
|
||||||
db: RefCell::new(db),
|
db: RefCell::new(db),
|
||||||
cache: StatementCache::with_capacity(STATEMENT_CACHE_DEFAULT_CAPACITY),
|
cache: StatementCache::with_capacity(STATEMENT_CACHE_DEFAULT_CAPACITY),
|
||||||
|
transaction_behavior: TransactionBehavior::Deferred
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -997,6 +1001,7 @@ impl Connection {
|
|||||||
Ok(Connection {
|
Ok(Connection {
|
||||||
db: RefCell::new(db),
|
db: RefCell::new(db),
|
||||||
cache: StatementCache::with_capacity(STATEMENT_CACHE_DEFAULT_CAPACITY),
|
cache: StatementCache::with_capacity(STATEMENT_CACHE_DEFAULT_CAPACITY),
|
||||||
|
transaction_behavior: TransactionBehavior::Deferred
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,10 +1,18 @@
|
|||||||
use crate::{Connection, Result};
|
use crate::{Connection, Result};
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
|
||||||
|
impl Connection {
|
||||||
|
/// Set the default transaction behavior for the connection.
|
||||||
|
pub fn set_transaction_behavior(&mut self, behavior: TransactionBehavior) {
|
||||||
|
self.transaction_behavior = behavior;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Options for transaction behavior. See [BEGIN
|
/// Options for transaction behavior. See [BEGIN
|
||||||
/// TRANSACTION](http://www.sqlite.org/lang_transaction.html) for details.
|
/// TRANSACTION](http://www.sqlite.org/lang_transaction.html) for details.
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
|
|
||||||
pub enum TransactionBehavior {
|
pub enum TransactionBehavior {
|
||||||
/// DEFERRED means that the transaction does not actually start until the
|
/// DEFERRED means that the transaction does not actually start until the
|
||||||
/// database is first accessed.
|
/// database is first accessed.
|
||||||
@ -414,7 +422,7 @@ impl Connection {
|
|||||||
/// Will return `Err` if the underlying SQLite call fails.
|
/// Will return `Err` if the underlying SQLite call fails.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn transaction(&mut self) -> Result<Transaction<'_>> {
|
pub fn transaction(&mut self) -> Result<Transaction<'_>> {
|
||||||
Transaction::new(self, TransactionBehavior::Deferred)
|
Transaction::new(self, self.transaction_behavior)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Begin a new transaction with a specified behavior.
|
/// Begin a new transaction with a specified behavior.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user