pub struct ConnectionOptions {
pub open_mode: OpenMode,
pub key: Option<String>,
pub busy_timeout: Duration,
pub foreign_keys: bool,
pub journal_mode: JournalMode,
pub synchronous: Synchronous,
pub fullfsync: bool,
pub read_uncommitted: bool,
}Expand description
Configuration to apply consistently to direct and pooled connections.
Defaults preserve the journal mode, enable foreign keys, wait up to five seconds for locks, and disable dirty reads. Writable connections use EXTRA synchronization and, on macOS, full filesystem synchronization. Cache sizes, page sizes, temporary storage, and cipher compatibility settings are left to the backend or format.
The key must be applied before reading the database, and the busy timeout before operations that may need locks. A schema read is required to validate decryption. Connection-local settings must be applied to every new pooled connection.
use rbox_db::connection::{ConnectionOptions, OpenMode};
let options = ConnectionOptions {
open_mode: OpenMode::ReadWrite,
key: Some("database-specific passphrase".into()),
..ConnectionOptions::default()
};Fields§
§open_mode: OpenModeAccess mode. Defaults to read-write; creation requires an explicit opt-in.
The opener must select the matching SQLite URI mode (ro, rw, or rwc).
setup_connection can restrict queries but cannot change file-open flags.
key: Option<String>SQLCipher passphrase supplied by the database format; None means no key.
Redacted from debug output. This value is a passphrase, not a raw-key SQL literal.
busy_timeout: DurationTime to wait for database locks. Defaults to five seconds.
foreign_keys: boolEnforce foreign-key constraints on this connection. Defaults to true.
journal_mode: JournalModeJournal policy. Defaults to preserving the current mode.
synchronous: SynchronousSynchronization policy for writes. Defaults to Synchronous::Extra.
fullfsync: boolRequest full filesystem synchronization where supported (macOS).
Defaults to true on macOS and false elsewhere. When enabled, it also
covers checkpoints, so no separate checkpoint synchronization option is needed.
read_uncommitted: boolPermit dirty reads where SQLite supports them. Defaults to false.
Implementations§
Source§impl ConnectionOptions
impl ConnectionOptions
Sourcepub fn for_export() -> Self
pub fn for_export() -> Self
Options for creating a device export with DELETE journaling and durable writes.
Supply the export format’s key before connecting. To open an existing export
while preserving its journal mode, use Self::default and select the desired
OpenMode instead.
Sourcepub fn open_mode(&mut self, open_mode: OpenMode) -> &mut Self
pub fn open_mode(&mut self, open_mode: OpenMode) -> &mut Self
Set the access mode. Defaults to read-write.
Creation requires an explicit opt-in. Read-only connections must preserve the journal mode.
Sourcepub fn key(&mut self, key: String) -> &mut Self
pub fn key(&mut self, key: String) -> &mut Self
Set the SQLCipher passphrase. Defaults to None.
Sourcepub fn busy_timeout(&mut self, busy_timeout: Duration) -> &mut Self
pub fn busy_timeout(&mut self, busy_timeout: Duration) -> &mut Self
Set the busy timeout. Defaults to five seconds.
Sourcepub fn foreign_keys(&mut self, foreign_keys: bool) -> &mut Self
pub fn foreign_keys(&mut self, foreign_keys: bool) -> &mut Self
Enable or disable foreign-key enforcement. Defaults to true.
Sourcepub fn journal_mode(&mut self, journal_mode: JournalMode) -> &mut Self
pub fn journal_mode(&mut self, journal_mode: JournalMode) -> &mut Self
Set the journal mode. Defaults to preserving the current mode.
Sourcepub fn synchronous(&mut self, synchronous: Synchronous) -> &mut Self
pub fn synchronous(&mut self, synchronous: Synchronous) -> &mut Self
Set the synchronization policy for writes. Defaults to Synchronous::Extra.
Sourcepub fn fullfsync(&mut self, fullfsync: bool) -> &mut Self
pub fn fullfsync(&mut self, fullfsync: bool) -> &mut Self
Enable or disable full filesystem synchronization where supported (macOS). Defaults to true on macOS and false elsewhere.
Sourcepub fn read_uncommitted(&mut self, read_uncommitted: bool) -> &mut Self
pub fn read_uncommitted(&mut self, read_uncommitted: bool) -> &mut Self
Enable or disable dirty reads where SQLite supports them. Defaults to false.
Trait Implementations§
Source§impl Clone for ConnectionOptions
impl Clone for ConnectionOptions
Source§impl CustomizeConnection<SqliteConnection, Error> for ConnectionOptions
Apply settings to each new physical pool connection, before it is handed out.
impl CustomizeConnection<SqliteConnection, Error> for ConnectionOptions
Apply settings to each new physical pool connection, before it is handed out.
Match the manager URL’s access mode to open_mode. The customizer runs once per
connection, not on every checkout; callers must not leave changed PRAGMAs behind.
use diesel::r2d2::ConnectionManager;
use rbox_db::connection::{ConnectionOptions, DbConn, DbPool, OpenMode};
let manager = ConnectionManager::<DbConn>::new("file:library.db?mode=ro");
let options = ConnectionOptions { open_mode: OpenMode::ReadOnly, ..Default::default() };
let pool = DbPool::builder()
.connection_customizer(Box::new(options))
.build(manager)?;Source§impl Debug for ConnectionOptions
impl Debug for ConnectionOptions
Auto Trait Implementations§
impl Freeze for ConnectionOptions
impl RefUnwindSafe for ConnectionOptions
impl Send for ConnectionOptions
impl Sync for ConnectionOptions
impl Unpin for ConnectionOptions
impl UnsafeUnpin for ConnectionOptions
impl UnwindSafe for ConnectionOptions
Blanket Implementations§
Source§impl<T> AggregateExpressionMethods for T
impl<T> AggregateExpressionMethods for T
Source§fn aggregate_distinct(self) -> Self::Outputwhere
Self: DistinctDsl,
fn aggregate_distinct(self) -> Self::Outputwhere
Self: DistinctDsl,
DISTINCT modifier for aggregate functions Read moreSource§fn aggregate_all(self) -> Self::Outputwhere
Self: AllDsl,
fn aggregate_all(self) -> Self::Outputwhere
Self: AllDsl,
ALL modifier for aggregate functions Read moreSource§fn aggregate_filter<P>(self, f: P) -> Self::Output
fn aggregate_filter<P>(self, f: P) -> Self::Output
Source§fn aggregate_order<O>(self, o: O) -> Self::Outputwhere
Self: OrderAggregateDsl<O>,
fn aggregate_order<O>(self, o: O) -> Self::Outputwhere
Self: OrderAggregateDsl<O>,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> IntoSql for T
impl<T> IntoSql for T
Source§fn into_sql<T>(self) -> Self::Expression
fn into_sql<T>(self) -> Self::Expression
self to an expression for Diesel’s query builder. Read moreSource§fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
&self to an expression for Diesel’s query builder. Read more