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, DB, T> DBAdapterManager<'q, DB, T>
impl<'q, 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 async fn count_page<'c, Adapter>(
&'q mut self,
page_size: i64,
db_adapter: Adapter,
) -> Result<PageInfo, Error>
pub async fn count_page<'c, 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 render_sql_with_adapter<'c, Adapter>(
template: T,
db_adapter: Adapter,
page_no: Option<i64>,
page_size: Option<i64>,
) -> Result<(String, Option<DB::Arguments<'q>>, impl DatabaseDialect, impl Executor<'c, Database = DB>), Error>where
Adapter: BackendDB<'c, DB>,
pub async fn render_sql_with_adapter<'c, Adapter>(
template: T,
db_adapter: Adapter,
page_no: Option<i64>,
page_size: Option<i64>,
) -> Result<(String, Option<DB::Arguments<'q>>, impl DatabaseDialect, impl Executor<'c, Database = DB>), Error>where
Adapter: BackendDB<'c, DB>,
Core SQL rendering method with pagination support
Sourcepub async fn execute<'c, Adapter>(
&'q mut self,
db_adapter: Adapter,
) -> Result<DB::QueryResult, Error>where
Adapter: BackendDB<'c, DB>,
pub async fn execute<'c, Adapter>(
&'q mut self,
db_adapter: Adapter,
) -> Result<DB::QueryResult, Error>where
Adapter: BackendDB<'c, DB>,
like sqlx::Query::execute Execute the query and return the number of rows affected.
Sourcepub async fn execute_many<'c, 'e, Adapter>(
&'q mut self,
db_adapter: Adapter,
) -> BoxStream<'e, Result<DB::QueryResult, Error>>where
Adapter: BackendDB<'c, DB>,
'c: 'e,
'q: 'e,
pub async fn execute_many<'c, 'e, Adapter>(
&'q mut self,
db_adapter: Adapter,
) -> BoxStream<'e, Result<DB::QueryResult, Error>>where
Adapter: BackendDB<'c, DB>,
'c: 'e,
'q: 'e,
like sqlx::Query::execute_many Execute multiple queries and return the rows affected from each query, in a stream.
Sourcepub async fn fetch<'c, 'e, Adapter>(
&'q mut self,
db_adapter: Adapter,
) -> BoxStream<'e, Result<DB::Row, Error>>where
Adapter: BackendDB<'c, DB>,
'c: 'e,
'q: 'e,
pub async fn fetch<'c, 'e, Adapter>(
&'q mut self,
db_adapter: Adapter,
) -> BoxStream<'e, Result<DB::Row, Error>>where
Adapter: BackendDB<'c, DB>,
'c: 'e,
'q: 'e,
like sqlx::Query::fetch Execute the query and return the generated results as a stream.
Sourcepub async fn fetch_many<'c, 'e, Adapter>(
&'q mut self,
db_adapter: Adapter,
) -> BoxStream<'e, Result<Either<DB::QueryResult, DB::Row>, Error>>where
Adapter: BackendDB<'c, DB>,
'c: 'e,
'q: 'e,
pub async fn fetch_many<'c, 'e, Adapter>(
&'q mut self,
db_adapter: Adapter,
) -> BoxStream<'e, Result<Either<DB::QueryResult, DB::Row>, Error>>where
Adapter: BackendDB<'c, DB>,
'c: 'e,
'q: 'e,
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<'c, Adapter>(
&'q mut self,
db_adapter: Adapter,
) -> Result<Vec<DB::Row>, Error>where
Adapter: BackendDB<'c, DB>,
pub async fn fetch_all<'c, Adapter>(
&'q mut self,
db_adapter: Adapter,
) -> Result<Vec<DB::Row>, Error>where
Adapter: BackendDB<'c, DB>,
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<'c, Adapter>(
&'q mut self,
db_adapter: Adapter,
) -> Result<DB::Row, Error>where
Adapter: BackendDB<'c, DB>,
pub async fn fetch_one<'c, Adapter>(
&'q mut self,
db_adapter: Adapter,
) -> Result<DB::Row, Error>where
Adapter: BackendDB<'c, DB>,
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<'c, Adapter>(
&'q mut self,
db_adapter: Adapter,
) -> Result<Option<DB::Row>, Error>where
Adapter: BackendDB<'c, DB>,
pub async fn fetch_optional<'c, Adapter>(
&'q mut self,
db_adapter: Adapter,
) -> Result<Option<DB::Row>, Error>where
Adapter: BackendDB<'c, DB>,
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<'c, 'e, Adapter, O>(
&'q mut self,
db_adapter: Adapter,
) -> BoxStream<'e, Result<O, Error>>
pub async fn fetch_as<'c, 'e, Adapter, O>( &'q mut self, db_adapter: Adapter, ) -> BoxStream<'e, Result<O, Error>>
like sqlx::QueryAs::fetch Execute the query and return the generated results as a stream.
Sourcepub async fn fetch_many_as<'c, 'e, Adapter, O>(
&'q mut self,
db_adapter: Adapter,
) -> BoxStream<'e, Result<Either<DB::QueryResult, O>, Error>>
pub async fn fetch_many_as<'c, 'e, 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<'c, Adapter, O>(
&'q mut self,
db_adapter: Adapter,
) -> Result<Vec<O>, Error>
pub async fn fetch_all_as<'c, 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<'c, Adapter, O>(
&'q mut self,
db_adapter: Adapter,
) -> Result<O, Error>
pub async fn fetch_one_as<'c, 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<'c, Adapter, O>(
&'q mut self,
db_adapter: Adapter,
) -> Result<Option<O>, Error>
pub async fn fetch_optional_as<'c, 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> 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