Skip to main content

DatabaseSession

Struct DatabaseSession 

Source
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 explicit read guards before writing. Reacquire a handle from the host after an await. A handle supplies neither a snapshot nor a transaction spanning calls. Each batch uses the ordinary enclosing-message commit rules.

Each insert, replace or delete commits a separate batch in the enclosing message. Submit dependent changes together:

let mut batch = Batch::new();
batch.replace(first)?;
batch.replace(second)?;
session.commit(batch)?;

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

Source

pub fn new(database: Database) -> Self

Wrap an already-created or reopened database. Its allocation remains leased until the last handle is dropped.

Source

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.

Source

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.

Source

pub fn query<'a, E: Entity>(&self) -> Query<'a, E>

Build a live query over this attachment. Execution sees writes committed before the terminal call. An exclusive borrow at execution returns Error::BorrowConflict. The builder owns a session handle and borrows only its predicate and cursor inputs.

Source

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.

Source

pub fn get_many<E: Entity>( &self, keys: &[E::Key], ) -> Result<Vec<Option<E>>, Error>

Read up to 32 primary keys in input order, preserving duplicates and missing slots.

§Errors

Returns a borrow conflict or the original Database::get_many error.

Source

pub fn get_unique<K: UniqueKey>( &self, key: &K, ) -> Result<Option<K::Entity>, Error>

Look up an owned row using a generated unique key, such as UserByIssuerAndSubject { issuer, subject }.

§Errors

Propagates session borrow, schema, key admission and row integrity errors.

Source

pub fn insert<E: Entity>(&self, row: &E) -> Result<(), Error>

Insert one entity as one batch.

§Errors

Propagates batch preparation and commit errors.

Source

pub fn insert_input<I: InsertInput>(&self, input: I) -> Result<I::Entity, Error>

Insert one generated input, applying its schema defaults. Returns the row after commit succeeds. Managed fields receive the current operation time.

§Errors

Propagates input preparation and commit errors.

Source

pub fn replace<E: Entity>(&self, row: &E) -> Result<(), Error>

Replace one existing entity. A changed row receives the current managed update time.

§Errors

Propagates batch preparation and commit errors.

Source

pub fn delete<E: Entity>(&self, key: E::Key) -> Result<(), Error>

Delete one entity by primary key as one batch.

§Errors

Propagates batch preparation and commit errors.

Source

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.

Trait Implementations§

Source§

impl Clone for DatabaseSession

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<E: Entity> QuerySession<E> for DatabaseSession

Source§

fn entity_query<'a>(&self) -> Query<'a, E>

Build a live query. The builder owns the selected store handle.

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.