[−][src]Trait sqlx::prelude::Connection
Represents a single database connection.
Associated Types
type Database: Database
type Options: ConnectOptions
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 backend
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.
fn begin(
&mut self
) -> Pin<Box<dyn Future<Output = Result<Transaction<'_, Self::Database>, Error>> + Send>>
&mut self
) -> Pin<Box<dyn Future<Output = Result<Transaction<'_, Self::Database>, Error>> + Send>>
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, T, E, F, Fut>(
&'c mut self,
f: F
) -> Pin<Box<dyn Future<Output = Result<T, E>> + 'f + Send>> where
'c: 'f,
E: From<Error> + Send,
F: FnOnce(&mut <Self::Database as Database>::Connection) -> Fut + Send + 'f,
Fut: Future<Output = Result<T, E>> + Send,
T: Send,
&'c mut self,
f: F
) -> Pin<Box<dyn Future<Output = Result<T, E>> + 'f + Send>> where
'c: 'f,
E: From<Error> + Send,
F: FnOnce(&mut <Self::Database as Database>::Connection) -> Fut + Send + 'f,
Fut: Future<Output = Result<T, E>> + Send,
T: 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
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send>> where
Self::Database: HasStatementCache,
&mut self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send>> where
Self::Database: HasStatementCache,
Removes all statements from the cache, closing them on the server if needed.
fn connect(
url: &str
) -> Pin<Box<dyn Future<Output = Result<Self, Error>> + 'static + Send>>
url: &str
) -> Pin<Box<dyn Future<Output = Result<Self, Error>> + 'static + Send>>
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
) -> Pin<Box<dyn Future<Output = Result<Self, Error>> + Send>>
options: &Self::Options
) -> Pin<Box<dyn Future<Output = Result<Self, Error>> + Send>>
Establish a new database connection with the provided options.
Implementors
impl Connection for AnyConnection
[src]
type Database = Any
type Options = AnyConnectOptions
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]
fn begin(
&mut self
) -> Pin<Box<dyn Future<Output = Result<Transaction<'_, <AnyConnection as Connection>::Database>, Error>> + Send>> where
AnyConnection: Sized,
[src]
&mut self
) -> Pin<Box<dyn Future<Output = Result<Transaction<'_, <AnyConnection as Connection>::Database>, Error>> + Send>> where
AnyConnection: Sized,
fn cached_statements_size(&self) -> usize
[src]
fn clear_cached_statements(
&mut self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send>>
[src]
&mut self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send>>
impl Connection for MssqlConnection
[src]
type Database = Mssql
type Options = MssqlConnectOptions
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]
fn begin(
&mut self
) -> Pin<Box<dyn Future<Output = Result<Transaction<'_, <MssqlConnection as Connection>::Database>, Error>> + Send>> where
MssqlConnection: Sized,
[src]
&mut self
) -> Pin<Box<dyn Future<Output = Result<Transaction<'_, <MssqlConnection as Connection>::Database>, Error>> + Send>> where
MssqlConnection: Sized,
impl Connection for MySqlConnection
[src]
type Database = MySql
type Options = MySqlConnectOptions
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]
fn cached_statements_size(&self) -> usize
[src]
fn clear_cached_statements(
&mut self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send>>
[src]
&mut self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send>>
fn begin(
&mut self
) -> Pin<Box<dyn Future<Output = Result<Transaction<'_, <MySqlConnection as Connection>::Database>, Error>> + Send>> where
MySqlConnection: Sized,
[src]
&mut self
) -> Pin<Box<dyn Future<Output = Result<Transaction<'_, <MySqlConnection as Connection>::Database>, Error>> + Send>> where
MySqlConnection: Sized,
impl Connection for PgConnection
[src]
type Database = Postgres
type Options = PgConnectOptions
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]
fn begin(
&mut self
) -> Pin<Box<dyn Future<Output = Result<Transaction<'_, <PgConnection as Connection>::Database>, Error>> + Send>> where
PgConnection: Sized,
[src]
&mut self
) -> Pin<Box<dyn Future<Output = Result<Transaction<'_, <PgConnection as Connection>::Database>, Error>> + Send>> where
PgConnection: Sized,
fn cached_statements_size(&self) -> usize
[src]
fn clear_cached_statements(
&mut self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send>>
[src]
&mut self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send>>
impl Connection for SqliteConnection
[src]
type Database = Sqlite
type Options = SqliteConnectOptions
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]
fn begin(
&mut self
) -> Pin<Box<dyn Future<Output = Result<Transaction<'_, <SqliteConnection as Connection>::Database>, Error>> + Send>> where
SqliteConnection: Sized,
[src]
&mut self
) -> Pin<Box<dyn Future<Output = Result<Transaction<'_, <SqliteConnection as Connection>::Database>, Error>> + Send>> where
SqliteConnection: Sized,
fn cached_statements_size(&self) -> usize
[src]
fn clear_cached_statements(
&mut self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send>>
[src]
&mut self
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send>>