pub struct SelectQueryBuilder<'args, DB, Model>where
    DB: Database,{
    pub query: Select,
    /* private fields */
}

Fields§

§query: Select

Implementations§

source§

impl<'args, DB, M> SelectQueryBuilder<'args, DB, M>where M: Sized + Send + Sync + Unpin + for<'r> FromRow<'r, DB::Row> + 'static + Model<DB>, DB: Database + DatabaseMetadata, <DB as HasArguments<'args>>::Arguments: IntoArguments<'args, DB>,

source

pub async fn fetch_all<'executor, E>(self, db: E) -> Result<Vec<M>>where E: Executor<'executor, Database = DB>,

source

pub async fn fetch_one<'executor, E>(self, db: E) -> Result<M>where E: Executor<'executor, Database = DB>,

source

pub async fn fetch_optional<'executor, E>(self, db: E) -> Result<Option<M>>where E: Executor<'executor, Database = DB>,

source

pub fn with(self, name: &str, query: &str) -> Self

source

pub fn select(self, column: impl Into<String>) -> Self

Add a column to the query. Note you typically don’t need this, as creating a query from Model::select will automatically add that model’s columns.

Arguments
  • column - The column to add. Examples: “id”, “name”, “person.*”
source

pub fn where_(self, clause: &'static str) -> Self

Add a WHERE clause to the query. Do not use format! to add parameters. Instead, use ? as the placeholder, and add parameters with bind.

Postgres users: You can (and should) use ? as the placeholder. You might not have a defined numerical order for your parameters, preventing $ syntax. Upon execution, the query builder replaces ? with $<N>. If you need the same parameter multiple times, you should bind it multiple times. Arguments aren’t moved, so this doesn’t incur a memory cost. If you still want to re-use parameters, you can use $ placeholders. However, don’t mix ? and $<N> placeholders, as they will conflict.

Arguments
  • clause - The clause to add. Examples: “id = ?”, “name = ?”, “person.id = ?”
source

pub fn where_bind<T>(self, clause: &'static str, value: T) -> Selfwhere T: 'args + Send + Type<DB> + Encode<'args, DB>,

Convenience method to add a WHERE and bind a value in one call.

source

pub fn dangerous_where(self, clause: &str) -> Self

Dangerous because it takes a string that could be user crafted. You should prefer .where_ which takes a &’static str, and pass arguments with .bind().

source

pub fn join(self, join_description: JoinDescription) -> Self

source

pub fn having(self, clause: &str) -> Self

Add a HAVING clause to the query.

source

pub fn group_by(self, clause: &str) -> Self

Add a GROUP BY clause to the query.

Arguments:
  • clause: The GROUP BY clause to add. Examples: “id”, “id, date”, “1, 2, ROLLUP(3)”
source

pub fn order_by(self, clause: &str, direction: Direction) -> Self

Add an ORDER BY clause to the query.

Arguments:
  • clause: The ORDER BY clause to add. “created_at DESC”, “id ASC NULLS FIRST”
  • direction: Direction::Asc or Direction::Desc
source

pub fn order_asc(self, clause: &str) -> Self

source

pub fn order_desc(self, clause: &str) -> Self

source

pub fn limit(self, limit: usize) -> Self

Add a limit to the query.

source

pub fn offset(self, offset: usize) -> Self

Add an offset to the query.

source

pub fn bind<T>(self, value: T) -> Selfwhere T: 'args + Send + Type<DB> + Encode<'args, DB>,

Bind an argument to the query.

source

pub fn into_query_and_args( self ) -> Result<(String, QueryBuilderArgs<'args, DB>)>

Trait Implementations§

source§

impl<'args, DB: Database + DatabaseMetadata, M: Model<DB>> Default for SelectQueryBuilder<'args, DB, M>

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'args, DB, Model> RefUnwindSafe for SelectQueryBuilder<'args, DB, Model>where Model: RefUnwindSafe, <DB as HasArguments<'args>>::Arguments: RefUnwindSafe,

§

impl<'args, DB, Model> Send for SelectQueryBuilder<'args, DB, Model>where Model: Send,

§

impl<'args, DB, Model> Sync for SelectQueryBuilder<'args, DB, Model>where Model: Sync, <DB as HasArguments<'args>>::Arguments: Sync,

§

impl<'args, DB, Model> Unpin for SelectQueryBuilder<'args, DB, Model>where Model: Unpin,

§

impl<'args, DB, Model> UnwindSafe for SelectQueryBuilder<'args, DB, Model>where Model: UnwindSafe, <DB as HasArguments<'args>>::Arguments: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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> Same<T> for T

§

type Output = T

Should always be Self
source§

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

§

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 Twhere U: TryFrom<T>,

§

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