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 raw_sql<'a>(
&self,
query_string: &'a str,
bind_params: Option<&[Value<'a>]>,
transaction: Option<&mut Transaction>,
) -> Result<Vec<Row>, Error>
👎Deprecated: Use Executor::execute
instead
pub async fn raw_sql<'a>( &self, query_string: &'a str, bind_params: Option<&[Value<'a>]>, transaction: Option<&mut Transaction>, ) -> Result<Vec<Row>, Error>
Executor::execute
insteadExecute raw SQL statements on the database.
If possible, the statement is executed as prepared statement.
To bind parameter, use ? as placeholder in SQLite and MySQL and $1, $2, $n in Postgres.
Parameter:
query_string
: Reference to a valid SQL query.bind_params
: Optional list of values to bind in the query.transaction
: Optional transaction to execute the query on.
Returns a list of rows. If there are no values to retrieve, an empty list is returned.
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>>
TransactionGuard
returned by ensure_transaction
Source§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,
Source§fn into_dyn(self) -> DynamicExecutor<'executor>
fn into_dyn(self) -> DynamicExecutor<'executor>
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>>
TransactionGuard
. Read moreAuto Trait Implementations§
impl Freeze for Database
impl !RefUnwindSafe for Database
impl Send for Database
impl Sync for Database
impl Unpin for Database
impl !UnwindSafe 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
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>
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>
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