Connection

Trait Connection 

Source
pub trait Connection {
    type Exec<'c>: Executor<'c, Database = Any>
       where Self: 'c;

    // Required methods
    fn executor<'c>(&'c mut self) -> Self::Exec<'c>;
    fn driver(&self) -> Drivers;
}
Expand description

A trait representing a database connection or transaction.

This trait abstracts over Database (pool) and Transaction types, allowing the QueryBuilder to work seamlessly with both. It uses Generic Associated Types (GATs) to handle the lifetimes of the executor references correctly.

Required Associated Types§

Source

type Exec<'c>: Executor<'c, Database = Any> where Self: 'c

The type of the executor returned by this connection.

This uses GATs to bind the lifetime of the executor ('c) to the lifetime of the borrow of the connection (&'c mut self).

Required Methods§

Source

fn executor<'c>(&'c mut self) -> Self::Exec<'c>

Returns a mutable reference to the SQLx executor.

§Returns

An executor capable of running SQL queries (either a Pool or a Transaction).

Source

fn driver(&self) -> Drivers

Returns the driver type associated with this connection.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<'a, T> Connection for &'a mut T
where T: Connection + Send + Unpin,

Implementation of Connection for any mutable reference to a type implementing Connection.

This allows passing &mut Database or &mut Transaction where Connection is expected.

Source§

type Exec<'c> = <T as Connection>::Exec<'c> where Self: 'c

Source§

fn driver(&self) -> Drivers

Source§

fn executor<'c>(&'c mut self) -> Self::Exec<'c>

Implementors§

Source§

impl Connection for Database

Implementation of Connection for the main Database struct.

Uses the internal connection pool to execute queries.

Source§

type Exec<'c> = &'c Pool<Any>

Source§

impl<'a> Connection for Transaction<'a>

Implementation of Connection for a Transaction.

Allows the QueryBuilder to use a transaction for executing queries. Supports generic borrow lifetimes to allow multiple operations within the same transaction scope.

Source§

type Exec<'c> = &'c mut AnyConnection where Self: 'c