[−][src]Trait sqlx_core::connection::Connection
Represents a single database connection.
Associated Types
type Database: Database
type Options: ConnectOptions<Connection = Self>
Required methods
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.
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,
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<'c: 'f, 'f, T, E, F, Fut>(
&'c mut self,
f: F
) -> BoxFuture<'f, Result<T, E>> where
Self: Sized,
T: Send,
F: FnOnce(&mut <Self::Database as Database>::Connection) -> Fut + Send + 'f,
E: From<Error> + Send,
Fut: Future<Output = Result<T, E>> + Send,
&'c mut self,
f: F
) -> BoxFuture<'f, Result<T, E>> where
Self: Sized,
T: Send,
F: FnOnce(&mut <Self::Database as Database>::Connection) -> Fut + Send + 'f,
E: From<Error> + Send,
Fut: Future<Output = Result<T, E>> + Send,
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.
fn cached_statements_size(&self) -> usize where
Self::Database: HasStatementCache,
Self::Database: HasStatementCache,
The number of statements currently cached in the connection.
fn clear_cached_statements(&mut self) -> BoxFuture<Result<(), Error>> where
Self::Database: HasStatementCache,
Self::Database: HasStatementCache,
Removes all statements from the cache, closing them on the server if needed.
fn connect(url: &str) -> BoxFuture<'static, Result<Self, Error>> where
Self: Sized,
Self: Sized,
Establish a new database connection.
A value of Options is parsed from the provided connection string. This parsing
is database-specific.
fn connect_with(options: &Self::Options) -> BoxFuture<Result<Self, Error>> where
Self: Sized,
Self: Sized,
Establish a new database connection with the provided options.