pub struct DBAdapterManager<'q, DB, T>where
DB: Database,
T: SqlTemplate<'q, DB>,{ /* private fields */ }Expand description
Database adapter manager handling SQL rendering and execution
§Generic Parameters
'q: Query lifetimeDB: Database typeT: SQL template type
Implementations§
Source§impl<'q, DB, T> DBAdapterManager<'q, DB, T>where
DB: Database,
T: SqlTemplate<'q, DB>,
impl<'q, DB, T> DBAdapterManager<'q, DB, T>where
DB: Database,
T: SqlTemplate<'q, DB>,
Source§impl<'q, 'c, 'e, DB, T> DBAdapterManager<'q, DB, T>
impl<'q, 'c, 'e, DB, T> DBAdapterManager<'q, DB, T>
Sourcepub fn set_persistent(self, persistent: bool) -> Self
pub fn set_persistent(self, persistent: bool) -> Self
Configures query persistence (default: true)
Sourcepub fn count<Adapter>(
&'q mut self,
db_adapter: Adapter,
) -> BoxFuture<'e, Result<i64, Error>>
pub fn count<Adapter>( &'q mut self, db_adapter: Adapter, ) -> BoxFuture<'e, Result<i64, Error>>
Sourcepub async fn count_page<Adapter>(
&'q mut self,
page_size: i64,
db_adapter: Adapter,
) -> Result<PageInfo, Error>
pub async fn count_page<Adapter>( &'q mut self, page_size: i64, db_adapter: Adapter, ) -> Result<PageInfo, Error>
Calculates complete pagination metadata
§Arguments
page_size- Records per pagedb_adapter- Database connection adapter
Sourcepub async fn execute<Adapter>(
&'q mut self,
db_adapter: Adapter,
) -> Result<DB::QueryResult, Error>where
Adapter: BackendDB<'c, DB> + 'c,
pub async fn execute<Adapter>(
&'q mut self,
db_adapter: Adapter,
) -> Result<DB::QueryResult, Error>where
Adapter: BackendDB<'c, DB> + 'c,
like sqlx::Query::execute Execute the query and return the number of rows affected.
Sourcepub fn execute_many<Adapter>(
&'q mut self,
db_adapter: Adapter,
) -> impl Stream<Item = Result<DB::QueryResult, Error>>where
Adapter: BackendDB<'c, DB> + 'c,
pub fn execute_many<Adapter>(
&'q mut self,
db_adapter: Adapter,
) -> impl Stream<Item = Result<DB::QueryResult, Error>>where
Adapter: BackendDB<'c, DB> + 'c,
like sqlx::Query::execute_many Execute multiple queries and return the rows affected from each query, in a stream.
Sourcepub fn fetch<Adapter>(
&'q mut self,
db_adapter: Adapter,
) -> impl Stream<Item = Result<DB::Row, Error>>where
Adapter: BackendDB<'c, DB> + 'c,
pub fn fetch<Adapter>(
&'q mut self,
db_adapter: Adapter,
) -> impl Stream<Item = Result<DB::Row, Error>>where
Adapter: BackendDB<'c, DB> + 'c,
like sqlx::Query::fetch Execute the query and return the generated results as a stream.
Sourcepub fn fetch_many<Adapter>(
&'q mut self,
db_adapter: Adapter,
) -> BoxStream<'e, Result<Either<DB::QueryResult, DB::Row>, Error>>where
Adapter: BackendDB<'c, DB> + 'c,
pub fn fetch_many<Adapter>(
&'q mut self,
db_adapter: Adapter,
) -> BoxStream<'e, Result<Either<DB::QueryResult, DB::Row>, Error>>where
Adapter: BackendDB<'c, DB> + 'c,
like sqlx::Query::fetch_many Execute multiple queries and return the generated results as a stream.
For each query in the stream, any generated rows are returned first,
then the QueryResult with the number of rows affected.
Sourcepub async fn fetch_all<Adapter>(
&'q mut self,
db_adapter: Adapter,
) -> Result<Vec<DB::Row>, Error>where
Adapter: BackendDB<'c, DB> + 'c,
pub async fn fetch_all<Adapter>(
&'q mut self,
db_adapter: Adapter,
) -> Result<Vec<DB::Row>, Error>where
Adapter: BackendDB<'c, DB> + 'c,
like sqlx::Query::fetch_all
Execute the query and return all the resulting rows collected into a Vec.
§Note: beware result set size.
This will attempt to collect the full result set of the query into memory.
To avoid exhausting available memory, ensure the result set has a known upper bound,
e.g. using LIMIT.
Sourcepub async fn fetch_one<Adapter>(
&'q mut self,
db_adapter: Adapter,
) -> Result<DB::Row, Error>where
Adapter: BackendDB<'c, DB> + 'c,
pub async fn fetch_one<Adapter>(
&'q mut self,
db_adapter: Adapter,
) -> Result<DB::Row, Error>where
Adapter: BackendDB<'c, DB> + 'c,
like sqlx::Query::fetch_one
Execute the query, returning the first row or Error::RowNotFound otherwise.
§Note: for best performance, ensure the query returns at most one row.
Depending on the driver implementation, if your query can return more than one row, it may lead to wasted CPU time and bandwidth on the database server.
Even when the driver implementation takes this into account, ensuring the query returns at most one row can result in a more optimal query plan.
If your query has a WHERE clause filtering a unique column by a single value, you’re good.
Otherwise, you might want to add LIMIT 1 to your query.
Sourcepub async fn fetch_optional<Adapter>(
&'q mut self,
db_adapter: Adapter,
) -> Result<Option<DB::Row>, Error>where
Adapter: BackendDB<'c, DB> + 'c,
pub async fn fetch_optional<Adapter>(
&'q mut self,
db_adapter: Adapter,
) -> Result<Option<DB::Row>, Error>where
Adapter: BackendDB<'c, DB> + 'c,
like sqlx::Query::fetch_optional
Execute the query, returning the first row or None otherwise.
§Note: for best performance, ensure the query returns at most one row.
Depending on the driver implementation, if your query can return more than one row, it may lead to wasted CPU time and bandwidth on the database server.
Even when the driver implementation takes this into account, ensuring the query returns at most one row can result in a more optimal query plan.
If your query has a WHERE clause filtering a unique column by a single value, you’re good.
Otherwise, you might want to add LIMIT 1 to your query.
Sourcepub async fn fetch_as<Adapter, O>(
&'q mut self,
db_adapter: Adapter,
) -> impl Stream<Item = Result<O, Error>>
pub async fn fetch_as<Adapter, O>( &'q mut self, db_adapter: Adapter, ) -> impl Stream<Item = Result<O, Error>>
like sqlx::QueryAs::fetch Execute the query and return the generated results as a stream.
Sourcepub fn fetch_many_as<Adapter, O>(
&'q mut self,
db_adapter: Adapter,
) -> BoxStream<'e, Result<Either<DB::QueryResult, O>, Error>>
pub fn fetch_many_as<Adapter, O>( &'q mut self, db_adapter: Adapter, ) -> BoxStream<'e, Result<Either<DB::QueryResult, O>, Error>>
like sqlx::QueryAs::fetch_many Execute multiple queries and return the generated results as a stream from each query, in a stream.
Sourcepub async fn fetch_all_as<Adapter, O>(
&'q mut self,
db_adapter: Adapter,
) -> Result<Vec<O>, Error>
pub async fn fetch_all_as<Adapter, O>( &'q mut self, db_adapter: Adapter, ) -> Result<Vec<O>, Error>
like sqlx::QueryAs::fetch_all
Execute the query and return all the resulting rows collected into a Vec.
§Note: beware result set size.
This will attempt to collect the full result set of the query into memory.
To avoid exhausting available memory, ensure the result set has a known upper bound,
e.g. using LIMIT.
Sourcepub async fn fetch_one_as<Adapter, O>(
&'q mut self,
db_adapter: Adapter,
) -> Result<O, Error>
pub async fn fetch_one_as<Adapter, O>( &'q mut self, db_adapter: Adapter, ) -> Result<O, Error>
like sqlx::QueryAs::fetch_one
Execute the query, returning the first row or Error::RowNotFound otherwise.
§Note: for best performance, ensure the query returns at most one row.
Depending on the driver implementation, if your query can return more than one row, it may lead to wasted CPU time and bandwidth on the database server.
Even when the driver implementation takes this into account, ensuring the query returns at most one row can result in a more optimal query plan.
If your query has a WHERE clause filtering a unique column by a single value, you’re good.
Otherwise, you might want to add LIMIT 1 to your query.
Sourcepub async fn fetch_optional_as<Adapter, O>(
&'q mut self,
db_adapter: Adapter,
) -> Result<Option<O>, Error>
pub async fn fetch_optional_as<Adapter, O>( &'q mut self, db_adapter: Adapter, ) -> Result<Option<O>, Error>
like sqlx::QueryAs::fetch_optional
Execute the query, returning the first row or None otherwise.
§Note: for best performance, ensure the query returns at most one row.
Depending on the driver implementation, if your query can return more than one row, it may lead to wasted CPU time and bandwidth on the database server.
Even when the driver implementation takes this into account, ensuring the query returns at most one row can result in a more optimal query plan.
If your query has a WHERE clause filtering a unique column by a single value, you’re good.
Otherwise, you might want to add LIMIT 1 to your query.
Auto Trait Implementations§
impl<'q, DB, T> Freeze for DBAdapterManager<'q, DB, T>where
T: Freeze,
impl<'q, DB, T> RefUnwindSafe for DBAdapterManager<'q, DB, T>where
T: RefUnwindSafe,
DB: RefUnwindSafe,
impl<'q, DB, T> Send for DBAdapterManager<'q, DB, T>
impl<'q, DB, T> Sync for DBAdapterManager<'q, DB, T>
impl<'q, DB, T> Unpin for DBAdapterManager<'q, DB, T>where
T: Unpin,
impl<'q, DB, T> UnsafeUnpin for DBAdapterManager<'q, DB, T>where
T: UnsafeUnpin,
impl<'q, DB, T> UnwindSafe for DBAdapterManager<'q, DB, T>where
T: UnwindSafe,
DB: RefUnwindSafe,
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> 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