pub struct DatabaseSession(/* private fields */);Expand description
A cloneable handle to one attached database and its existing storage lease.
The host attaches once using Self::new and hands each caller a clone.
Cloning takes no database borrow and performs no storage access.
Use a handle within one synchronous message execution. Drop read guards and
query builders before a write or an await, and reacquire a handle from the
host in a callback. A handle supplies neither a snapshot nor a transaction
spanning calls. Each batch uses the ordinary enclosing-message commit rules.
Engine work and output limits apply to each query. Cloning creates no budget. Hosts enforcing a cumulative request allowance must share the same allowance across helpers in that request and establish a fresh one at the next boundary.
Implementations§
Source§impl DatabaseSession
impl DatabaseSession
Sourcepub fn new(database: Database) -> Self
pub fn new(database: Database) -> Self
Wrap an already-created or reopened database. Its allocation remains leased until the last handle is dropped.
Sourcepub fn try_into_database(self) -> Result<Database, Self>
pub fn try_into_database(self) -> Result<Database, Self>
Recover the attached database for a lifecycle operation requiring ownership.
§Errors
Returns this same handle if another handle still owns the attachment.
Sourcepub fn read(&self) -> Result<Ref<'_, Database>, Error>
pub fn read(&self) -> Result<Ref<'_, Database>, Error>
Borrow the database for fluent queries or a sequence of synchronous reads.
A builder from read.query::<E>() borrows this guard. Commits can resume
after the guard is dropped, even if several session handles still exist.
§Errors
Returns Error::BorrowConflict if a commit has exclusive access.
Sourcepub fn get<E: Entity>(&self, key: E::Key) -> Result<Option<E>, Error>
pub fn get<E: Entity>(&self, key: E::Key) -> Result<Option<E>, Error>
Read an owned entity by primary key, releasing the borrow before returning.
§Errors
Returns a borrow conflict or the original Database::get error.
Sourcepub fn commit(&self, batch: Batch) -> Result<(), Error>
pub fn commit(&self, batch: Batch) -> Result<(), Error>
Commit one batch through the attached database.
§Errors
Returns Error::BorrowConflict before mutation if a borrow is active,
or the original Database::commit error.