Skip to main content

Connection

Trait Connection 

Source
pub trait Connection: Executor {
    // Required methods
    fn connect(
        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<'_>>>;

    // Provided methods
    fn sanitize_url(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( url: Cow<'static, str>, ) -> impl Future<Output = Result<<Self::Driver as Driver>::Connection>>
where Self: Sized,

Create a connection (or pool) to the given 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<'_>>>

Begin a transaction scope tied to this connection.

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

Provided Methods§

Source

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

Source

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

Disconnect and release the underlying session(s).

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.

Implementors§