pub struct Database(/* private fields */);Expand description
Implementations§
Source§impl Database
impl Database
Sourcepub async fn connect(
configuration: DatabaseConfiguration,
) -> Result<Self, Error>
pub async fn connect( configuration: DatabaseConfiguration, ) -> Result<Self, Error>
Connects to the database using configuration
Sourcepub async fn start_transaction(&self) -> Result<Transaction, Error>
pub async fn start_transaction(&self) -> Result<Transaction, Error>
Starts a new transaction
&mut Transaction implements Executor like &Database does
but its database operations can be reverted using Transaction::rollback
or simply dropping the transaction without calling Transaction::commit.
Sourcepub async fn close(self)
pub async fn close(self)
Closes the database connection
While calling this method is not strictly necessary, terminating your program without it might result in some final queries not being flushed properly.
This method consumes the database handle,
but actually all handles created using clone will become invalid after this call.
This means any further operation would result in an Err
Trait Implementations§
Source§impl Drop for Database
impl Drop for Database
Source§fn drop(&mut self)
fn drop(&mut self)
Checks whether Database::close has been called before the last instance is dropped
Source§impl<'executor> Executor<'executor> for &'executor Database
impl<'executor> Executor<'executor> for &'executor Database
Source§type EnsureTransactionFuture = Pin<Box<dyn Future<Output = Result<TransactionGuard<'executor>, Error>> + Send + 'executor>>
type EnsureTransactionFuture = Pin<Box<dyn Future<Output = Result<TransactionGuard<'executor>, Error>> + Send + 'executor>>
A future producing a
TransactionGuard returned by ensure_transactionSource§fn execute<'data, 'result, Q>(
self,
query: String,
values: Vec<Value<'data>>,
) -> Q::Result<'result>where
Q: QueryStrategy,
'executor: 'result,
'data: 'result,
fn execute<'data, 'result, Q>(
self,
query: String,
values: Vec<Value<'data>>,
) -> Q::Result<'result>where
Q: QueryStrategy,
'executor: 'result,
'data: 'result,
Executes a raw SQL query Read more
Source§fn into_dyn(self) -> DynamicExecutor<'executor>
fn into_dyn(self) -> DynamicExecutor<'executor>
Convenience method to convert into a “
dyn Executor”Source§fn ensure_transaction(
self,
) -> Pin<Box<dyn Future<Output = Result<TransactionGuard<'executor>, Error>> + Send + 'executor>>
fn ensure_transaction( self, ) -> Pin<Box<dyn Future<Output = Result<TransactionGuard<'executor>, Error>> + Send + 'executor>>
Ensure a piece of code is run inside a transaction using a
TransactionGuard. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for Database
impl !UnwindSafe for Database
impl Freeze for Database
impl Send for Database
impl Sync for Database
impl Unpin for Database
impl UnsafeUnpin for Database
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