pub struct Database(/* private fields */);
Expand description
Main API wrapper.
All operations can be started with methods of this struct.
Implementations§
Source§impl Database
impl Database
Sourcepub async fn connect(
configuration: DatabaseConfiguration,
) -> Result<Self, Error>
pub async fn connect( configuration: DatabaseConfiguration, ) -> Result<Self, Error>
Connect 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>
pub async fn raw_sql<'a>( &self, query_string: &'a str, bind_params: Option<&[Value<'a>]>, transaction: Option<&mut Transaction>, ) -> Result<Vec<Row>, Error>
Execute 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>
Entry point for a Transaction
.
Trait Implementations§
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_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,
Execute a query Read more
Source§fn ensure_transaction(
self,
) -> BoxFuture<'executor, Result<TransactionGuard<'executor>, Error>>
fn ensure_transaction( self, ) -> BoxFuture<'executor, Result<TransactionGuard<'executor>, Error>>
Ensure a piece of code is run inside a transaction using a
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
Mutably borrows from an owned value. Read more
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