Skip to main content

PooledConnection

Struct PooledConnection 

Source
pub struct PooledConnection<D: Driver> { /* private fields */ }
Expand description

A database connection borrowed from a ConnectionPool.

Implements both Executor and Connection, so it can be used anywhere a plain connection is expected. Deref-coerces to the underlying driver connection (D::Connection) via Deref/DerefMut, giving access to any driver-specific extension methods.

The borrowed connection is automatically returned to the pool when this value is dropped. If you need to take full ownership of the connection outside pool management, call ConnectionPool::detach instead.

§Obtaining a PooledConnection

Call ConnectionPool::get or ConnectionPool::timeout_get on a pool:

let mut pool = PostgresDriver::new()
    .connect_pool("postgres://localhost/mydb".into(), PoolConfig::new())
    .await?;

let mut conn = pool.get().await?;
Tank::create_table(&mut conn, true, true).await?;

Trait Implementations§

Source§

impl<D: Driver> AsMut<<D as Driver>::Connection> for PooledConnection<D>

Source§

fn as_mut(&mut self) -> &mut D::Connection

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<D: Driver> AsRef<<D as Driver>::Connection> for PooledConnection<D>

Source§

fn as_ref(&self) -> &D::Connection

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<D: Driver> Connection for PooledConnection<D>

Source§

fn connect( _driver: &D, _url: Cow<'static, str>, ) -> impl Future<Output = Result<<D as Driver>::Connection>> + Send
where Self: Sized,

Establishes a connection (or pool) to the database specified by the URL. Read more
Source§

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

Starts a new transaction on this connection. Read more
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<()>> + Send
where Self: Sized,

Closes the connection and releases any session resources.
Source§

impl<D: Debug + Driver> Debug for PooledConnection<D>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<D: Driver> Deref for PooledConnection<D>

Source§

type Target = <D as Driver>::Connection

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<D: Driver> DerefMut for PooledConnection<D>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<D: Driver> Executor for PooledConnection<D>

Source§

type Driver = D

Associated driver.
Source§

fn accepts_multiple_statements(&self) -> bool

Checks if the driver supports multiple SQL statements in a single request.
Source§

fn driver(&self) -> D

Returns the driver instance associated with this executor.
Source§

fn prepare<'s>( &'s mut self, query: impl AsQuery<D> + 's, ) -> impl Future<Output = Result<Query<D>>> + Send

Prepares a query for execution, returning a handle to the prepared statement.
Source§

fn do_prepare( &mut self, sql: String, ) -> impl Future<Output = Result<Query<D>>> + Send

Internal hook for implementing prepared statement support.
Source§

fn run<'s>( &'s mut self, query: impl AsQuery<D> + 's, ) -> impl Stream<Item = Result<QueryResult>> + Send

Executes a query and streams the results (rows or affected counts).
Source§

fn fetch<'s>( &'s mut self, query: impl AsQuery<D> + 's, ) -> impl Stream<Item = Result<Row>> + Send

Executes a query and streams the resulting rows, ignoring affected counts.
Source§

fn execute<'s>( &'s mut self, query: impl AsQuery<D> + 's, ) -> impl Future<Output = Result<RowsAffected>> + Send

Executes a query and returns the total number of affected rows.
Source§

fn append<'a, E, It>( &mut self, entities: It, ) -> impl Future<Output = Result<RowsAffected>> + Send
where E: Entity + 'a, It: IntoIterator<Item = &'a E> + Send, <It as IntoIterator>::IntoIter: Send,

Efficiently inserts a collection of entities bypassing regular SQL execution when supported by the driver.

Auto Trait Implementations§

§

impl<D> !RefUnwindSafe for PooledConnection<D>

§

impl<D> !UnwindSafe for PooledConnection<D>

§

impl<D> Freeze for PooledConnection<D>
where <D as Driver>::Connection: Freeze,

§

impl<D> Send for PooledConnection<D>

§

impl<D> Sync for PooledConnection<D>
where <D as Driver>::Connection: Sync,

§

impl<D> Unpin for PooledConnection<D>
where <D as Driver>::Connection: Unpin,

§

impl<D> UnsafeUnpin for PooledConnection<D>
where <D as Driver>::Connection: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Casing<T> for T
where T: AsRef<str>,

Source§

fn to_case(&self, case: Case<'_>) -> String

Convert the string into the given case. It will reference self and create a new String with the same pattern and delimiter as case. It will split on boundaries defined at Boundary::defaults(). Read more
Source§

fn set_boundaries(&self, bs: &[Boundary]) -> StateConverter<'_, T>

Creates a StateConverter struct initialized with the boundaries provided. Read more
Source§

fn remove_boundaries(&self, bs: &[Boundary]) -> StateConverter<'_, T>

Creates a StateConverter struct initialized without the boundaries provided. Read more
Source§

fn from_case(&self, case: Case<'_>) -> StateConverter<'_, T>

Start the case conversion by storing the boundaries associated with the given case. Read more
Source§

fn remove_empty(&self) -> StateConverter<'_, T>

Creates a StateConverter with the RemoveEmpty pattern prepended. This filters out empty words before conversion, useful when splitting produces empty words from leading, trailing, and duplicate delimiters. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Parsable for T
where T: Deref, <T as Deref>::Target: Parsable,

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToHex for T
where T: AsRef<[u8]>,

Source§

fn encode_hex<U>(&self) -> U
where U: FromIterator<char>,

Encode the hex strict representing self into the result. Lower case letters are used (e.g. f9b4ca)
Source§

fn encode_hex_upper<U>(&self) -> U
where U: FromIterator<char>,

Encode the hex strict representing self into the result. Upper case letters are used (e.g. F9B4CA)
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.