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
impl ManagedConnection
pub fn open(path: &Path) -> Result<Self>
Sourcepub fn database_path(&self) -> Option<&Path>
pub fn database_path(&self) -> Option<&Path>
Return the backing database path for a file-backed connection.
pub fn open_encrypted(path: &Path, key: &str) -> Result<Self>
pub fn open_compressed( path: &Path, compression: SQLiteCompressionOptions, ) -> Result<Self>
pub fn open_compressed_encrypted( path: &Path, key: &str, compression: SQLiteCompressionOptions, ) -> Result<Self>
Sourcepub fn open_compressed_encrypted_with_anchor(
path: &Path,
key: &str,
compression: SQLiteCompressionOptions,
trusted_anchor: SQLiteCompressedContainerAnchor,
) -> Result<Self>
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.
pub fn open_in_memory() -> Result<Self>
Sourcepub fn new_session(&self) -> Self
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.
Sourcepub fn in_transaction(&self) -> bool
pub fn in_transaction(&self) -> bool
Whether this logical session currently owns a pinned transaction connection.
Sourcepub fn transaction_has_written(&self) -> Result<bool>
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.
Sourcepub fn data_version_monitor_is_nonblocking(&self) -> Result<bool>
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.
Sourcepub fn supports_concurrent_pinned_read_and_write(&self) -> bool
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.
Sourcepub fn data_version(&self) -> Result<Option<u64>>
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.
Sourcepub fn pin_transaction_snapshot(&self) -> Result<()>
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.
Sourcepub fn with<R>(&self, f: impl FnOnce(&Connection) -> Result<R>) -> Result<R>
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.
pub fn with_mut<R>( &self, f: impl FnOnce(&mut Connection) -> Result<R>, ) -> Result<R>
Sourcepub fn vacuum(&self) -> Result<()>
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.
Sourcepub fn begin_transaction(&self) -> Result<()>
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.
Sourcepub fn begin_deferred_transaction(&self) -> Result<()>
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.
pub fn commit_transaction(&self) -> Result<()>
pub fn rollback_transaction(&self) -> Result<()>
pub fn savepoint(&self, name: &str) -> Result<()>
pub fn release_savepoint(&self, name: &str) -> Result<()>
pub fn rollback_to_savepoint(&self, name: &str) -> Result<()>
Trait Implementations§
Source§impl Clone for ManagedConnection
impl Clone for ManagedConnection
Source§fn clone(&self) -> ManagedConnection
fn clone(&self) -> ManagedConnection
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more