pub struct DatabaseManager { /* private fields */ }Implementations§
Source§impl DatabaseManager
impl DatabaseManager
pub fn new(config: &Config) -> Self
pub async fn connect(&self) -> Result<DbConn, DbErr>
pub async fn connection(&self) -> Result<DbConn, DbErr>
Sourcepub async fn transaction<F, T>(&self, f: F) -> Result<T, DbErr>
pub async fn transaction<F, T>(&self, f: F) -> Result<T, DbErr>
Run a closure inside a database transaction.
If the closure returns Ok, the transaction is committed. If it
returns Err, the transaction is rolled back and the error is
propagated. The closure must be boxed with Box::pin because it
borrows the transaction handle:
ⓘ
let ok = db.transaction(|txn| Box::pin(async move {
Order::insert_into(txn).await?;
Ok(())
})).await?;Sourcepub async fn begin_transaction(&self) -> Result<DatabaseTransaction, DbErr>
pub async fn begin_transaction(&self) -> Result<DatabaseTransaction, DbErr>
Begin a new database transaction and return a handle to it.
The caller is responsible for calling commit() or rollback().
ⓘ
let txn = db.begin_transaction().await?;
// ... run queries via `txn` (it implements `ConnectionTrait`) ...
txn.commit().await?;pub async fn disconnect(&self)
pub async fn migrate<M: MigratorTrait>(&self) -> Result<(), DbErr>
pub async fn migrate_fresh<M: MigratorTrait>(&self) -> Result<(), DbErr>
pub async fn migrate_rollback<M: MigratorTrait>( &self, steps: Option<u32>, ) -> Result<(), DbErr>
pub async fn migrate_status<M: MigratorTrait>(&self) -> Result<(), DbErr>
pub async fn seed<S: Seeder>(&self) -> Result<(), Box<dyn Error>>
pub async fn seed_all(&self) -> Result<(), Box<dyn Error>>
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for DatabaseManager
impl !UnwindSafe for DatabaseManager
impl Freeze for DatabaseManager
impl Send for DatabaseManager
impl Sync for DatabaseManager
impl Unpin for DatabaseManager
impl UnsafeUnpin for DatabaseManager
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,
impl<T> Event for T
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
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