Skip to main content

ManagedConnection

Struct ManagedConnection 

Source
pub struct ManagedConnection { /* private fields */ }
Expand description

Logical SQLite session backed by a bounded physical connection pool. Cloning preserves session/transaction affinity; call Self::new_session for an independently isolated transaction context.

Implementations§

Source§

impl ManagedConnection

Source

pub fn open(path: &Path) -> Result<Self>

Source

pub fn database_path(&self) -> Option<&Path>

Return the backing database path for a file-backed connection.

Source

pub fn open_encrypted(path: &Path, key: &str) -> Result<Self>

Source

pub fn open_compressed( path: &Path, compression: SQLiteCompressionOptions, ) -> Result<Self>

Source

pub fn open_compressed_encrypted( path: &Path, key: &str, compression: SQLiteCompressionOptions, ) -> Result<Self>

Source

pub fn open_compressed_encrypted_with_anchor( path: &Path, key: &str, compression: SQLiteCompressionOptions, trusted_anchor: SQLiteCompressedContainerAnchor, ) -> Result<Self>

Open an encrypted compressed database while enforcing an exact trusted external state anchor in the VFS main-file open path.

Source

pub fn open_in_memory() -> Result<Self>

Source

pub fn new_session(&self) -> Self

Create an independent logical session over the same database pool. Explicit transactions started on either session are isolated and never capture operations issued through the other session.

Source

pub fn in_transaction(&self) -> bool

Whether this logical session currently owns a pinned transaction connection.

Source

pub fn transaction_has_written(&self) -> Result<bool>

Whether the currently pinned transaction has upgraded to a write transaction. Callers use this to enforce read-only execution boundaries before COMMIT rather than inferring writes from SQL shape.

Source

pub fn data_version_monitor_is_nonblocking(&self) -> Result<bool>

Whether this session’s independent Self::data_version monitor can read without contending with the currently pinned transaction.

The compressed VFS deliberately maps rollback-journal RESERVED and stronger locks to one whole-file exclusive lock. Once an immediate transaction has entered SQLite’s write state, a second connection from the same pool therefore cannot even read PRAGMA data_version. Callers must use the pinned connection and conservatively refresh their caches instead of waiting on a lock held by themselves. WAL connections and compressed read transactions permit the independent monitor.

Source

pub fn supports_concurrent_pinned_read_and_write(&self) -> bool

Whether one pooled connection may retain a read snapshot while another writes. Plain and encrypted SQLite databases use WAL; compressed containers use rollback journaling and therefore require a detached engine snapshot before writer promotion.

Source

pub fn data_version(&self) -> Result<Option<u64>>

Database change counter observed on one stable connection shared by every logical session over this pool. The value changes when another SQLite connection commits. In-memory databases have no independent connections and therefore return None.

Source

pub fn pin_transaction_snapshot(&self) -> Result<()>

Establish the database snapshot for the active transaction without depending on the caller’s first user query. BEGIN DEFERRED alone does not start a read transaction, so a writer could otherwise commit after the engine checks its cache generations but before the first catalog read. Reading sqlite_schema is database-wide and keeps the operation independent of any application table.

Source

pub fn with<R>(&self, f: impl FnOnce(&Connection) -> Result<R>) -> Result<R>

Run a closure using this session. Outside a transaction the closure checks out a pooled connection; inside a transaction every clone is routed to the session’s pinned connection.

Source

pub fn with_mut<R>( &self, f: impl FnOnce(&mut Connection) -> Result<R>, ) -> Result<R>

Source

pub fn vacuum(&self) -> Result<()>

Rewrite the SQLite database into its minimum-sized file. SQLite requires VACUUM to run in autocommit mode, so the session write gate makes the transaction check and maintenance command one atomic session operation.

Source

pub fn begin_transaction(&self) -> Result<()>

Open an explicit (non-deferred) transaction. Subsequent auto-commit hosts (catalog writes, FTS index updates, …) all flow through the same connection so the transaction enclosing them is honoured. Use Self::commit_transaction / Self::rollback_transaction / Self::savepoint etc. for the lifecycle.

Source

pub fn begin_deferred_transaction(&self) -> Result<()>

Open a deferred transaction. Read-only SQL statements use this mode so WAL readers do not take the single writer reservation; if a scalar routine performs a write, SQLite upgrades the same transaction and still preserves the statement’s atomic boundary.

Source

pub fn commit_transaction(&self) -> Result<()>

Source

pub fn rollback_transaction(&self) -> Result<()>

Source

pub fn savepoint(&self, name: &str) -> Result<()>

Source

pub fn release_savepoint(&self, name: &str) -> Result<()>

Source

pub fn rollback_to_savepoint(&self, name: &str) -> Result<()>

Trait Implementations§

Source§

impl Clone for ManagedConnection

Source§

fn clone(&self) -> ManagedConnection

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

Auto Trait Implementations§

Blanket Implementations§

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> 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> Same for T

Source§

type Output = T

Should always be Self
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.