pub enum Db<'a> {
Pool(&'a PgPool),
Conn(&'a mut PgConnection),
}Expand description
Where a function gets its connection: the pool, or a connection the caller holds, usually an open transaction, so one function serves both.
impl sqlx::Acquire says the same, but its associated types stop the future
being Send, which Axum handlers and tokio::spawn need.
use axa_sqlx::{Db, sqlx};
async fn count(db: impl Into<Db<'_>>) -> Result<i64, sqlx::Error> {
let mut conn = db.into().acquire().await?;
sqlx::query_scalar("SELECT count(*) FROM items")
.fetch_one(&mut *conn)
.await
}Variants§
Pool(&'a PgPool)
Take a connection from the pool for the length of the call.
Conn(&'a mut PgConnection)
Use the caller’s connection.
Implementations§
Trait Implementations§
Source§impl<'a> From<&'a mut PgConnection> for Db<'a>
impl<'a> From<&'a mut PgConnection> for Db<'a>
Source§fn from(conn: &'a mut PgConnection) -> Self
fn from(conn: &'a mut PgConnection) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl<'a> !RefUnwindSafe for Db<'a>
impl<'a> !UnwindSafe for Db<'a>
impl<'a> Forget for Db<'a>
impl<'a> Freeze for Db<'a>
impl<'a> Send for Db<'a>
impl<'a> Sync for Db<'a>
impl<'a> Unpin for Db<'a>
impl<'a> UnsafeUnpin for Db<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more