Trait sqlx::Connection [−][src]
pub trait Connection: Send { type Database: Database; type Options: ConnectOptions; fn close(
self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'static + Send, Global>>; fn ping(
&mut self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send, Global>>; fn begin(
&mut self
) -> Pin<Box<dyn Future<Output = Result<Transaction<'_, Self::Database>, Error>> + Send, Global>>; fn transaction<'a, F, R, E>(
&'a mut self,
callback: F
) -> Pin<Box<dyn Future<Output = Result<R, E>> + 'a + Send, Global>>
where
F: for<'c> FnOnce(&'c mut Transaction<'_, Self::Database>) -> Pin<Box<dyn Future<Output = Result<R, E>> + 'c + Send, Global>> + 'a + Send + Sync,
R: Send,
E: From<Error> + Send, { ... } fn cached_statements_size(&self) -> usize
where
Self::Database: HasStatementCache, { ... } fn clear_cached_statements(
&mut self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send, Global>>
where
Self::Database: HasStatementCache, { ... } fn connect(
url: &str
) -> Pin<Box<dyn Future<Output = Result<Self, Error>> + 'static + Send, Global>> { ... } fn connect_with(
options: &Self::Options
) -> Pin<Box<dyn Future<Output = Result<Self, Error>> + Send, Global>> { ... } }
Expand description
Represents a single database connection.
Associated Types
Required methods
fn close(
self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'static + Send, Global>>
[src]
fn close(
self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'static + Send, Global>>
[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.
Provided methods
fn transaction<'a, F, R, E>(
&'a mut self,
callback: F
) -> Pin<Box<dyn Future<Output = Result<R, E>> + 'a + Send, Global>> where
F: for<'c> FnOnce(&'c mut Transaction<'_, Self::Database>) -> Pin<Box<dyn Future<Output = Result<R, E>> + 'c + Send, Global>> + 'a + Send + Sync,
R: Send,
E: From<Error> + Send,
[src]
fn transaction<'a, F, R, E>(
&'a mut self,
callback: F
) -> Pin<Box<dyn Future<Output = Result<R, E>> + 'a + Send, Global>> where
F: for<'c> FnOnce(&'c mut Transaction<'_, Self::Database>) -> Pin<Box<dyn Future<Output = Result<R, E>> + 'c + Send, Global>> + 'a + Send + Sync,
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
fn cached_statements_size(&self) -> usize where
Self::Database: HasStatementCache,
[src]
fn cached_statements_size(&self) -> usize where
Self::Database: HasStatementCache,
[src]The number of statements currently cached in the connection.
fn clear_cached_statements(
&mut self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send, Global>> where
Self::Database: HasStatementCache,
[src]
fn clear_cached_statements(
&mut self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send, Global>> where
Self::Database: HasStatementCache,
[src]Removes all statements from the cache, closing them on the server if needed.
Implementors
impl Connection for AnyConnection
[src]
impl Connection for AnyConnection
[src]type Database = Any
type Options = AnyConnectOptions
pub fn close(
self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'static + Send, Global>>
[src]
self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'static + Send, Global>>
pub fn ping(
&mut self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send, Global>>
[src]
&mut self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send, Global>>
pub fn begin(
&mut self
) -> Pin<Box<dyn Future<Output = Result<Transaction<'_, <AnyConnection as Connection>::Database>, Error>> + Send, Global>> where
AnyConnection: Sized,
[src]
&mut self
) -> Pin<Box<dyn Future<Output = Result<Transaction<'_, <AnyConnection as Connection>::Database>, Error>> + Send, Global>> where
AnyConnection: Sized,
pub fn cached_statements_size(&self) -> usize
[src]
pub fn clear_cached_statements(
&mut self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send, Global>>
[src]
&mut self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send, Global>>
impl Connection for MssqlConnection
[src]
impl Connection for MssqlConnection
[src]type Database = Mssql
type Options = MssqlConnectOptions
pub fn close(
self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'static + Send, Global>>
[src]
self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'static + Send, Global>>
pub fn ping(
&mut self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send, Global>>
[src]
&mut self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send, Global>>
pub fn begin(
&mut self
) -> Pin<Box<dyn Future<Output = Result<Transaction<'_, <MssqlConnection as Connection>::Database>, Error>> + Send, Global>> where
MssqlConnection: Sized,
[src]
&mut self
) -> Pin<Box<dyn Future<Output = Result<Transaction<'_, <MssqlConnection as Connection>::Database>, Error>> + Send, Global>> where
MssqlConnection: Sized,
impl Connection for MySqlConnection
[src]
impl Connection for MySqlConnection
[src]type Database = MySql
type Options = MySqlConnectOptions
pub fn close(
self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'static + Send, Global>>
[src]
self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'static + Send, Global>>
pub fn ping(
&mut self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send, Global>>
[src]
&mut self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send, Global>>
pub fn cached_statements_size(&self) -> usize
[src]
pub fn clear_cached_statements(
&mut self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send, Global>>
[src]
&mut self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send, Global>>
pub fn begin(
&mut self
) -> Pin<Box<dyn Future<Output = Result<Transaction<'_, <MySqlConnection as Connection>::Database>, Error>> + Send, Global>> where
MySqlConnection: Sized,
[src]
&mut self
) -> Pin<Box<dyn Future<Output = Result<Transaction<'_, <MySqlConnection as Connection>::Database>, Error>> + Send, Global>> where
MySqlConnection: Sized,
impl Connection for PgConnection
[src]
impl Connection for PgConnection
[src]type Database = Postgres
type Options = PgConnectOptions
pub fn close(
self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'static + Send, Global>>
[src]
self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'static + Send, Global>>
pub fn ping(
&mut self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send, Global>>
[src]
&mut self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send, Global>>
pub fn begin(
&mut self
) -> Pin<Box<dyn Future<Output = Result<Transaction<'_, <PgConnection as Connection>::Database>, Error>> + Send, Global>> where
PgConnection: Sized,
[src]
&mut self
) -> Pin<Box<dyn Future<Output = Result<Transaction<'_, <PgConnection as Connection>::Database>, Error>> + Send, Global>> where
PgConnection: Sized,
pub fn cached_statements_size(&self) -> usize
[src]
pub fn clear_cached_statements(
&mut self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send, Global>>
[src]
&mut self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send, Global>>
impl Connection for SqliteConnection
[src]
impl Connection for SqliteConnection
[src]type Database = Sqlite
type Options = SqliteConnectOptions
pub fn close(
self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'static + Send, Global>>
[src]
self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + 'static + Send, Global>>
pub fn ping(
&mut self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send, Global>>
[src]
&mut self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send, Global>>
pub fn begin(
&mut self
) -> Pin<Box<dyn Future<Output = Result<Transaction<'_, <SqliteConnection as Connection>::Database>, Error>> + Send, Global>> where
SqliteConnection: Sized,
[src]
&mut self
) -> Pin<Box<dyn Future<Output = Result<Transaction<'_, <SqliteConnection as Connection>::Database>, Error>> + Send, Global>> where
SqliteConnection: Sized,
pub fn cached_statements_size(&self) -> usize
[src]
pub fn clear_cached_statements(
&mut self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send, Global>>
[src]
&mut self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send, Global>>