Trait Connection
pub trait Connection: Send {
type Database: Database;
type Options: ConnectOptions<Connection = Self>;
// Required methods
fn close(self) -> BoxFuture<'static, Result<(), Error>>;
fn close_hard(self) -> BoxFuture<'static, Result<(), Error>>;
fn ping(&mut self) -> BoxFuture<'_, Result<(), Error>>;
fn begin(
&mut self,
) -> BoxFuture<'_, Result<Transaction<'_, Self::Database>, Error>>
where Self: Sized;
// Provided methods
fn transaction<'a, F, R, E>(
&'a mut self,
callback: F,
) -> BoxFuture<'a, Result<R, E>>
where for<'c> F: FnOnce(&'c mut Transaction<'_, Self::Database>) -> BoxFuture<'c, Result<R, E>> + 'a + Send + Sync,
Self: Sized,
R: Send,
E: From<Error> + Send { ... }
fn connect(url: &str) -> BoxFuture<'static, Result<Self, Error>>
where Self: Sized { ... }
fn connect_with(
options: &Self::Options,
) -> BoxFuture<'_, Result<Self, Error>>
where Self: Sized { ... }
}Expand description
Represents a single database connection.
Required Associated Types§
type Database: Database
type Options: ConnectOptions<Connection = Self>
Required Methods§
fn close(self) -> BoxFuture<'static, Result<(), Error>>
fn close(self) -> BoxFuture<'static, Result<(), Error>>
Explicitly close this database connection.
This method is not required for safe and consistent operation. However, it is
recommended to call it instead of letting a connection drop as the database backend
will be faster at cleaning up resources.
For SQL Server, it is same as close_hard.
fn close_hard(self) -> BoxFuture<'static, Result<(), Error>>
fn close_hard(self) -> BoxFuture<'static, Result<(), Error>>
Immediately close the connection without sending a graceful shutdown.
This should still at least send a TCP FIN frame to let the server know we’re dying.
fn ping(&mut self) -> BoxFuture<'_, Result<(), Error>>
fn ping(&mut self) -> BoxFuture<'_, Result<(), Error>>
Checks if a connection to the database is still valid.
fn begin(
&mut self,
) -> BoxFuture<'_, Result<Transaction<'_, Self::Database>, Error>>where
Self: Sized,
fn begin(
&mut self,
) -> BoxFuture<'_, Result<Transaction<'_, Self::Database>, Error>>where
Self: Sized,
Begin a new transaction or establish a savepoint within the active transaction.
Returns a Transaction for controlling and tracking the new transaction.
Provided Methods§
fn transaction<'a, F, R, E>(
&'a mut self,
callback: F,
) -> BoxFuture<'a, Result<R, E>>
fn transaction<'a, F, R, E>( &'a mut self, callback: F, ) -> BoxFuture<'a, Result<R, E>>
Execute the function inside a transaction.
If the function returns an error, the transaction will be rolled back. If it does not return an error, the transaction will be committed.