pub struct Database<DB: SqlxDatabase> { /* private fields */ }Implementations§
Source§impl<DB> Database<DB>where
DB: SqlxDatabase + 'static,
Pool<DB>: Send + Sync,
<DB::Connection as Connection>::Options: FromStr,
<<DB::Connection as Connection>::Options as FromStr>::Err: Display,
impl<DB> Database<DB>where
DB: SqlxDatabase + 'static,
Pool<DB>: Send + Sync,
<DB::Connection as Connection>::Options: FromStr,
<<DB::Connection as Connection>::Options as FromStr>::Err: Display,
pub async fn connect(url: &str) -> Result<Self, DbError>
pub async fn init(url: &str) -> Result<(), DbError>
pub fn from_pool(pool: Pool<DB>) -> Self
pub fn set_global(database: Self) -> Result<(), DbError>
Sourcepub fn reset_global()
pub fn reset_global()
Removes this backend’s global pool. Intended for tests and deliberate
reconfiguration; existing cloned Database handles remain usable.
pub fn global() -> Result<Self, DbError>
pub fn pool(&self) -> &Pool<DB>
Sourcepub async fn transaction_global<T, F>(f: F) -> Result<T, DbError>
pub async fn transaction_global<T, F>(f: F) -> Result<T, DbError>
Runs a transaction using the pool installed by Self::init or
Self::set_global. This is the application-service entry point when
services and repositories must not carry a Database field.
pub async fn transaction<T, F>(&self, f: F) -> Result<T, DbError>
Trait Implementations§
Auto Trait Implementations§
impl<DB> !RefUnwindSafe for Database<DB>
impl<DB> !UnwindSafe for Database<DB>
impl<DB> Freeze for Database<DB>
impl<DB> Send for Database<DB>
impl<DB> Sync for Database<DB>
impl<DB> Unpin for Database<DB>
impl<DB> UnsafeUnpin for Database<DB>
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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