Skip to main content

Connection

Trait Connection 

Source
pub trait Connection: Executor {
    // Required methods
    fn connect(
        driver: &Self::Driver,
        url: Cow<'static, str>,
    ) -> impl Future<Output = Result<<Self::Driver as Driver>::Connection>>
       where Self: Sized;
    fn begin(
        &mut self,
    ) -> impl Future<Output = Result<<Self::Driver as Driver>::Transaction<'_>>>;
    fn duplicate(
        &self,
    ) -> impl Future<Output = Result<<Self::Driver as Driver>::Connection>>
       where Self: Sized;

    // Provided methods
    fn sanitize_url(
        driver: &Self::Driver,
        url: Cow<'static, str>,
    ) -> Result<Url>
       where Self: Sized { ... }
    fn disconnect(self) -> impl Future<Output = Result<()>>
       where Self: Sized { ... }
}
Expand description

A live database handle capable of executing queries and spawning transactions.

Extends Executor with connection and transaction management.

§Lifecycle

  • connect creates (or fetches) an underlying connection. It may eagerly establish network I/O; always await it.
  • begin starts a transaction scope. Commit/rollback MUST be awaited to guarantee resource release.

Required Methods§

Source

fn connect( driver: &Self::Driver, url: Cow<'static, str>, ) -> impl Future<Output = Result<<Self::Driver as Driver>::Connection>>
where Self: Sized,

Establishes a connection (or pool) to the database specified by the URL.

Implementations may perform I/O or validation during connect. Callers should treat this as a potentially expensive operation.

Source

fn begin( &mut self, ) -> impl Future<Output = Result<<Self::Driver as Driver>::Transaction<'_>>>

Starts a new transaction on this connection.

Must await commit or rollback to finalize the scope and release resources.

Source

fn duplicate( &self, ) -> impl Future<Output = Result<<Self::Driver as Driver>::Connection>>
where Self: Sized,

Provided Methods§

Source

fn sanitize_url(driver: &Self::Driver, url: Cow<'static, str>) -> Result<Url>
where Self: Sized,

Validates and normalizes the connection URL, handling special cases like in-memory databases.

Source

fn disconnect(self) -> impl Future<Output = Result<()>>
where Self: Sized,

Closes the connection and releases any session resources.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§