Skip to main content

SharedConnection

Struct SharedConnection 

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

Shared database access handle used by contexts, DbSets, raw SQL, and transactions.

A SharedConnection can wrap either one direct SQL Server connection or, behind the pool-bb8 feature, a pool. Runtime values such as audit values, soft-delete values, and the active tenant are stored alongside the physical connection handle and are preserved when derived contexts clone the handle.

Implementations§

Source§

impl SharedConnection

Source

pub fn from_connection( connection: MssqlConnection<TokioConnectionStream>, ) -> Self

Creates a shared handle from an already-open direct SQL Server connection.

Source

pub fn with_audit_provider(&self, provider: Arc<dyn AuditProvider>) -> Self

Returns a clone of this handle with an audit provider configured.

The provider is consulted by insert/update paths for entities declaring #[orm(audit = Audit)] after explicit mutation values and request values have had priority.

Source

pub fn with_audit_request_values( &self, request_values: AuditRequestValues, ) -> Self

Returns a clone of this handle with low-level audit request values.

Prefer with_audit_values(...) when using a struct derived with #[derive(AuditFields)].

Source

pub fn with_audit_values<V: AuditValues>(&self, values: V) -> Self

Returns a clone of this handle with typed audit request values.

The same struct used for #[derive(AuditFields)] can be passed here as runtime values. Values are converted to AuditRequestValues and keep the existing precedence rules.

Source

pub fn clear_audit_request_values(&self) -> Self

Returns a clone of this handle with audit request values cleared.

Source

pub fn with_soft_delete_provider( &self, provider: Arc<dyn SoftDeleteProvider>, ) -> Self

Returns a clone of this handle with a soft-delete provider configured.

The provider is used by delete paths for entities declaring #[orm(soft_delete = SoftDelete)].

Source

pub fn with_soft_delete_request_values( &self, request_values: SoftDeleteRequestValues, ) -> Self

Returns a clone of this handle with low-level soft-delete request values.

Prefer with_soft_delete_values(...) when using a struct derived with #[derive(SoftDeleteFields)].

Source

pub fn with_soft_delete_values<V: SoftDeleteValues>(&self, values: V) -> Self

Returns a clone of this handle with typed soft-delete request values.

The same struct used for #[derive(SoftDeleteFields)] can be passed here as runtime delete values.

Source

pub fn clear_soft_delete_request_values(&self) -> Self

Returns a clone of this handle with soft-delete request values cleared.

Source

pub fn with_tenant<T: TenantContext>(&self, tenant: T) -> Self

Returns a clone of this handle with an active tenant configured.

Tenant-scoped reads and writes fail closed if this tenant is absent, has a different column name, or has a value incompatible with the tenant column.

Source

pub fn clear_tenant(&self) -> Self

Returns a clone of this handle without an active tenant.

Source

pub async fn lock(&self) -> Result<SharedConnectionGuard<'_>, OrmError>

Acquires the underlying SQL Server connection for one operation.

Direct connections lock the shared mutex. Pooled connections acquire a connection from the pool for the lifetime of the returned guard.

Trait Implementations§

Source§

impl Clone for SharedConnection

Source§

fn clone(&self) -> SharedConnection

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

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more