pub type SharedConnection<'env> = Arc<Mutex<Connection<'env>>>;
Expand description
A convinient type alias in case you want to use a connection from multiple threads which share ownership of it.
Aliased Type§
pub struct SharedConnection<'env> { /* private fields */ }
Trait Implementations§
Source§impl<'env> ConnectionTransitions for SharedConnection<'env>
impl<'env> ConnectionTransitions for SharedConnection<'env>
Source§type StatementParent = Arc<Mutex<Connection<'env>>>
type StatementParent = Arc<Mutex<Connection<'env>>>
The type passed to crate::handles::StatementConnection to express ownership of the
connection.
Source§fn into_cursor(
self,
query: &str,
params: impl ParameterCollectionRef,
query_timeout_sec: Option<usize>,
) -> Result<Option<CursorImpl<StatementConnection<Self>>>, FailedStateTransition<Self>>
fn into_cursor( self, query: &str, params: impl ParameterCollectionRef, query_timeout_sec: Option<usize>, ) -> Result<Option<CursorImpl<StatementConnection<Self>>>, FailedStateTransition<Self>>
Similar to
crate::Connection::into_cursor
, yet it operates on an
Arc<Mutex<Connection>>
. Arc<Connection>
can be used if you want shared ownership of
connections. However, Arc<Connection>
is not Send
due to Connection
not being Sync
.
So sometimes you may want to wrap your Connection
into an Arc<Mutex<Connection>>
to
allow shared ownership of the connection across threads. This function allows you to create
a cursor from such a shared which also holds a strong reference to it. Read moreSource§fn into_prepared(
self,
query: &str,
) -> Result<Prepared<StatementConnection<Self>>, Error>
fn into_prepared( self, query: &str, ) -> Result<Prepared<StatementConnection<Self>>, Error>
Prepares an SQL statement which takes ownership of the connection. The advantage over
Connection::prepare
is, that you do not need to keep track of the lifetime of the
connection seperatly and can create types which do own the prepared query and only depend on
the lifetime of the environment. Read moreSource§fn into_preallocated(
self,
) -> Result<Preallocated<StatementConnection<Self>>, Error>
fn into_preallocated( self, ) -> Result<Preallocated<StatementConnection<Self>>, Error>
Creates a preallocated statement handle like
Connection::preallocate
. Yet the statement
also takes ownership of the connection.impl StatementParent for SharedConnection<'_>
§Safety:
Connection is guaranteed to be alive and in connected state for the lifetime of
SharedConnection
.