[][src]Trait sqlx_core::connection::Connection

pub trait Connection: Send {
    type Database: Database;
    type Options: ConnectOptions<Connection = Self>;
    pub fn close(self) -> BoxFuture<'static, Result<(), Error>>;
pub fn ping(&mut self) -> BoxFuture<'_, Result<(), Error>>;
pub fn begin(
        &mut self
    ) -> BoxFuture<'_, Result<Transaction<'_, Self::Database>, Error>>
    where
        Self: Sized
; pub fn transaction<F, R, E>(
        &mut self,
        callback: F
    ) -> BoxFuture<'_, Result<R, E>>
    where
        F: FnOnce(&'c mut Transaction<'_, Self::Database>) -> BoxFuture<'c, Result<R, E>> + 'static + Send + Sync,
        Self: Sized,
        R: Send,
        E: From<Error> + Send
, { ... }
pub fn cached_statements_size(&self) -> usize
    where
        Self::Database: HasStatementCache
, { ... }
pub fn clear_cached_statements(
        &mut self
    ) -> BoxFuture<'_, Result<(), Error>>
    where
        Self::Database: HasStatementCache
, { ... }
pub fn connect(url: &str) -> BoxFuture<'static, Result<Self, Error>>
    where
        Self: Sized
, { ... }
pub fn connect_with(
        options: &Self::Options
    ) -> BoxFuture<'_, Result<Self, Error>>
    where
        Self: Sized
, { ... } }

Represents a single database connection.

Associated Types

type Database: Database[src]

type Options: ConnectOptions<Connection = Self>[src]

Loading content...

Required methods

pub fn close(self) -> BoxFuture<'static, Result<(), Error>>[src]

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.

pub fn ping(&mut self) -> BoxFuture<'_, Result<(), Error>>[src]

Checks if a connection to the database is still valid.

pub fn begin(
    &mut self
) -> BoxFuture<'_, Result<Transaction<'_, Self::Database>, Error>> where
    Self: Sized
[src]

Begin a new transaction or establish a savepoint within the active transaction.

Returns a Transaction for controlling and tracking the new transaction.

Loading content...

Provided methods

pub fn transaction<F, R, E>(
    &mut self,
    callback: F
) -> BoxFuture<'_, Result<R, E>> where
    F: FnOnce(&'c mut Transaction<'_, Self::Database>) -> BoxFuture<'c, Result<R, E>> + 'static + Send + Sync,
    Self: Sized,
    R: Send,
    E: From<Error> + Send
[src]

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.

Example

use sqlx_core::connection::Connection;
use sqlx_core::error::Error;
use sqlx_core::executor::Executor;
use sqlx_core::postgres::{PgConnection, PgRow};
use sqlx_core::query::query;

conn.transaction(|conn|Box::pin(async move {
    query("select * from ..").fetch_all(conn).await
})).await

pub fn cached_statements_size(&self) -> usize where
    Self::Database: HasStatementCache
[src]

The number of statements currently cached in the connection.

pub fn clear_cached_statements(&mut self) -> BoxFuture<'_, Result<(), Error>> where
    Self::Database: HasStatementCache
[src]

Removes all statements from the cache, closing them on the server if needed.

pub fn connect(url: &str) -> BoxFuture<'static, Result<Self, Error>> where
    Self: Sized
[src]

Establish a new database connection.

A value of Options is parsed from the provided connection string. This parsing is database-specific.

pub fn connect_with(
    options: &Self::Options
) -> BoxFuture<'_, Result<Self, Error>> where
    Self: Sized
[src]

Establish a new database connection with the provided options.

Loading content...

Implementors

impl Connection for AnyConnection[src]

type Database = Any

type Options = AnyConnectOptions

impl Connection for MssqlConnection[src]

type Database = Mssql

type Options = MssqlConnectOptions

impl Connection for MySqlConnection[src]

type Database = MySql

type Options = MySqlConnectOptions

impl Connection for PgConnection[src]

type Database = Postgres

type Options = PgConnectOptions

impl Connection for SqliteConnection[src]

type Database = Sqlite

type Options = SqliteConnectOptions

Loading content...