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>>;
    fn begin(&mut self) -> impl Future<Output = Result<impl Transaction<'_>>>;

    // Provided method
    fn disconnect(self) -> impl Future<Output = Result<()>> { ... }
}
Expand description

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

This trait extends Executor adding functionality to acquire a connection and to begin transactional scopes.

Drivers implement concrete Connection types to expose backend-specific behavior (timeouts, pooling strategies, prepared statement caching, etc.).

§Lifecycle

  • connect creates (or fetches) an underlying connection. It may eagerly establish network I/O for validation; always await it.
  • begin starts a transaction returning an object implementing Transaction. 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>>

Create a connection (or pool) with at least one underlying session established to the given URL.

Source

fn begin(&mut self) -> impl Future<Output = Result<impl Transaction<'_>>>

Begin a transaction scope tied to the current connection.

Provided Methods§

Source

fn disconnect(self) -> impl Future<Output = Result<()>>

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§