DBAdapterManager

Struct DBAdapterManager 

Source
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 lifetime
  • DB: Database type
  • T: SQL template type

Implementations§

Source§

impl<'q, DB, T> DBAdapterManager<'q, DB, T>
where DB: Database, T: SqlTemplate<'q, DB>,

Source

pub fn new(template: T) -> Self

Creates new adapter with SQL buffer

§Arguments
  • template - SQL template instance
Source

pub fn sql(&self) -> &String

Source§

impl<'q, DB, T> DBAdapterManager<'q, DB, T>
where DB: Database, T: SqlTemplate<'q, DB>, i64: Encode<'q, DB> + Type<DB>,

Source

pub fn set_persistent(self, persistent: bool) -> Self

Configures query persistence (default: true)

Source

pub async fn count<'c, Adapter>( &'q mut self, db_adapter: Adapter, ) -> Result<i64, Error>
where Adapter: BackendDB<'c, DB>, (i64,): for<'r> FromRow<'r, DB::Row>,

Executes count query for pagination

§Arguments
  • db_adapter - Database connection adapter
Source

pub async fn count_page<'c, Adapter>( &'q mut self, page_size: i64, db_adapter: Adapter, ) -> Result<PageInfo, Error>
where Adapter: BackendDB<'c, DB>, (i64,): for<'r> FromRow<'r, DB::Row>,

Calculates complete pagination metadata

§Arguments
  • page_size - Records per page
  • db_adapter - Database connection adapter
Source

pub fn set_page(self, page_size: i64, page_no: i64) -> Self

Sets pagination parameters

Source

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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub async fn fetch_as<'c, 'e, Adapter, O>( &'q mut self, db_adapter: Adapter, ) -> BoxStream<'e, Result<O, Error>>
where Adapter: BackendDB<'c, DB>, O: Send + Unpin + for<'r> FromRow<'r, DB::Row> + 'e, 'c: 'e, 'q: 'e,

like sqlx::QueryAs::fetch Execute the query and return the generated results as a stream.

Source

pub async fn fetch_many_as<'c, 'e, Adapter, O>( &'q mut self, db_adapter: Adapter, ) -> BoxStream<'e, Result<Either<DB::QueryResult, O>, Error>>
where O: Send + Unpin + for<'r> FromRow<'r, DB::Row> + 'e, Adapter: BackendDB<'c, DB>, 'c: 'e, 'q: 'e,

like sqlx::QueryAs::fetch_many Execute multiple queries and return the generated results as a stream from each query, in a stream.

Source

pub async fn fetch_all_as<'c, Adapter, O>( &'q mut self, db_adapter: Adapter, ) -> Result<Vec<O>, Error>
where Adapter: BackendDB<'c, DB>, O: Send + Unpin + for<'r> FromRow<'r, DB::Row>,

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.

Source

pub async fn fetch_one_as<'c, Adapter, O>( &'q mut self, db_adapter: Adapter, ) -> Result<O, Error>
where Adapter: BackendDB<'c, DB>, O: Send + Unpin + for<'r> FromRow<'r, DB::Row>,

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.

Source

pub async fn fetch_optional_as<'c, Adapter, O>( &'q mut self, db_adapter: Adapter, ) -> Result<Option<O>, Error>
where Adapter: BackendDB<'c, DB>, O: Send + Unpin + for<'r> FromRow<'r, DB::Row>,

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>

§

impl<'q, DB, T> Send for DBAdapterManager<'q, DB, T>
where T: Send, DB: Sync,

§

impl<'q, DB, T> Sync for DBAdapterManager<'q, DB, T>
where T: Sync, DB: Sync,

§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,