Skip to main content

ConnectionOptions

Struct ConnectionOptions 

Source
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: OpenMode

Access 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: Duration

Time to wait for database locks. Defaults to five seconds.

§foreign_keys: bool

Enforce foreign-key constraints on this connection. Defaults to true.

§journal_mode: JournalMode

Journal policy. Defaults to preserving the current mode.

§synchronous: Synchronous

Synchronization policy for writes. Defaults to Synchronous::Extra.

§fullfsync: bool

Request 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: bool

Permit dirty reads where SQLite supports them. Defaults to false.

Implementations§

Source§

impl ConnectionOptions

Source

pub fn new() -> Self

Create a new instance with default settings.

Source

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.

Source

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.

Source

pub fn key(&mut self, key: String) -> &mut Self

Set the SQLCipher passphrase. Defaults to None.

Source

pub fn busy_timeout(&mut self, busy_timeout: Duration) -> &mut Self

Set the busy timeout. Defaults to five seconds.

Source

pub fn foreign_keys(&mut self, foreign_keys: bool) -> &mut Self

Enable or disable foreign-key enforcement. Defaults to true.

Source

pub fn journal_mode(&mut self, journal_mode: JournalMode) -> &mut Self

Set the journal mode. Defaults to preserving the current mode.

Source

pub fn synchronous(&mut self, synchronous: Synchronous) -> &mut Self

Set the synchronization policy for writes. Defaults to Synchronous::Extra.

Source

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.

Source

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

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

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§

fn on_acquire(&self, conn: &mut DbConn) -> Result<(), Error>

Called with connections immediately after they are returned from ManageConnection::connect. Read more
Source§

fn on_release(&self, conn: C)

Called with connections when they are removed from the pool. Read more
Source§

impl Debug for ConnectionOptions

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ConnectionOptions

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> AggregateExpressionMethods for T

Source§

fn aggregate_distinct(self) -> Self::Output
where Self: DistinctDsl,

DISTINCT modifier for aggregate functions Read more
Source§

fn aggregate_all(self) -> Self::Output
where Self: AllDsl,

ALL modifier for aggregate functions Read more
Source§

fn aggregate_filter<P>(self, f: P) -> Self::Output
where P: AsExpression<Bool>, Self: FilterDsl<<P as AsExpression<Bool>>::Expression>,

Add an aggregate function filter Read more
Source§

fn aggregate_order<O>(self, o: O) -> Self::Output
where Self: OrderAggregateDsl<O>,

Add an aggregate function order Read more
Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts 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>

Converts 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)

Converts &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)

Converts &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
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Sync + Send>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send> ⓘ

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoSql for T

Source§

fn into_sql<T>(self) -> Self::Expression

Convert self to an expression for Diesel’s query builder. Read more
Source§

fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
where &'a Self: AsExpression<T>, T: SqlType + TypedExpressionType,

Convert &self to an expression for Diesel’s query builder. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WindowExpressionMethods for T

Source§

fn over(self) -> Self::Output
where Self: OverDsl,

Turn a function call into a window function call Read more
Source§

fn window_filter<P>(self, f: P) -> Self::Output
where P: AsExpression<Bool>, Self: FilterDsl<<P as AsExpression<Bool>>::Expression>,

Add a filter to the current window function Read more
Source§

fn partition_by<E>(self, expr: E) -> Self::Output
where Self: PartitionByDsl<E>,

Add a partition clause to the current window function Read more
Source§

fn window_order<E>(self, expr: E) -> Self::Output
where Self: OrderWindowDsl<E>,

Add a order clause to the current window function Read more
Source§

fn frame_by<E>(self, expr: E) -> Self::Output
where Self: FrameDsl<E>,

Add a frame clause to the current window function Read more