[−][src]Trait sqlx::Connection
Represents a single database connection rather than a pool of database connections.
Connections can be manually established outside of a Pool
with Connect::connect
.
Prefer running queries from Pool
unless there is a specific need for a single, sticky
connection.
Required methods
fn close(
self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'static + Send>>
self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'static + Send>>
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 server
will be faster at cleaning up resources.
fn ping(&mut self) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send>>
Checks if a connection to the database is still valid.
Provided methods
fn begin(
self
) -> Pin<Box<dyn Future<Output = Result<Transaction<Self>, Error>> + 'static + Send>>
self
) -> Pin<Box<dyn Future<Output = Result<Transaction<Self>, Error>> + 'static + Send>>
Starts a new transaction.
Wraps this connection in Transaction
to manage the transaction lifecycle. To get the
original connection back, explicitly commit
or rollback
and this connection will
be returned.
let mut tx = conn.begin().await?; // conn is now inaccessible as its wrapped in a transaction let conn = tx.commit().await?; // conn is back now and out of the transaction
Implementors
impl Connection for MySqlConnection
[src]
fn close(
self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'static + Send>>
[src]
self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'static + Send>>
fn ping(&mut self) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send>>
[src]
impl Connection for PgConnection
[src]
fn close(
self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'static + Send>>
[src]
self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'static + Send>>
fn ping(&mut self) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send>>
[src]
impl Connection for SqliteConnection
[src]
fn close(
self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'static + Send>>
[src]
self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'static + Send>>
fn ping(&mut self) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send>>
[src]
impl<C> Connection for PoolConnection<C> where
C: Connect,
[src]
C: Connect,
fn close(
self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'static + Send>>
[src]
self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'static + Send>>
fn ping(&mut self) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send>>
[src]
impl<C> Connection for Transaction<C> where
C: Connection,
[src]
C: Connection,