Struct SelectQueryBuilder

Source
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) -> Self
where T: 'args + Send + Type<DB> + Encode<'args, DB>,

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

Source

pub fn where_bind_option<T>( self, clause: &'static str, value: Option<T>, ) -> Self
where T: 'args + Send + Type<DB> + Encode<'args, DB>,

Convenience method to add a WHERE and bind a optional value in one call. If Option is None, this clause will not be pushed

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) -> Self
where 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> Freeze for SelectQueryBuilder<'args, DB, Model>

§

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 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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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,

Source§

impl<T> MaybeSendSync for T