Skip to main content

Query

Struct Query 

Source
pub struct Query { /* private fields */ }
Expand description

Untyped query state used while shaping SQL structure.

This is the flexible form you use while adding joins, changing projections, or otherwise building a statement whose final row shape is not settled yet.

Implementations§

Source§

impl Query

Source

pub fn delete_query(self) -> Delete<()>

Source

pub async fn delete<E>(self, exec: E) -> Result<ExecResult, Error>
where E: Executor,

Source§

impl Query

Source

pub fn select<S>(self, s: S) -> Query
where S: LowerProject,

Replaces the current projection list.

Source

pub fn reset_select(&mut self)

Clears the current projection list.

Source

pub fn left_join<J>(self, join: J) -> Query
where J: LowerJoin,

Adds a left join to the current from clause.

Source

pub fn right_join<J>(self, join: J) -> Query
where J: LowerJoin,

Adds a right join to the current from clause.

Source

pub fn inner_join<J>(self, join: J) -> Query
where J: LowerJoin,

Adds an inner join to the current from clause.

Source

pub fn having<E>(self, e: E) -> Query
where E: LowerHaving,

Adds a having predicate combined with and.

Source

pub fn or_having<E>(self, e: E) -> Query
where E: LowerHaving,

Adds a having predicate combined with or.

Source

pub fn filter<E>(self, e: E) -> Query
where E: LowerFilter,

Adds a where predicate combined with and.

Source

pub fn or_filter<E>(self, e: E) -> Query
where E: LowerFilter,

Adds a where predicate combined with or.

Source

pub fn from<T>(table: T) -> Query
where T: LowerFrom,

Starts a query from the given source.

Source

pub fn union(self, other: impl Into<Query>) -> Query

Combines this query with another one using union.

Source

pub fn union_all(self, other: impl Into<Query>) -> Query

Combines this query with another one using union all.

Source

pub fn group_by<T>(self, by: T) -> Query
where T: LowerGroupBy,

Appends grouping expressions to group by.

Source

pub fn order_by<T>(self, by: T) -> Query
where T: LowerOrderBy,

Appends ordering expressions to order by.

Source

pub fn order_by_random(self) -> Query

Appends a random ordering expression.

Source

pub fn limit<E>(self, e: E) -> Query
where E: LowerCompatible<BigInt>,

Replaces any existing limit clause.

Source

pub fn reset_limit(&mut self)

Clears the current limit clause.

Source

pub fn offset<E>(self, e: E) -> Query
where E: LowerCompatible<BigInt>,

Replaces any existing offset clause.

Source

pub fn reset_offset(&mut self)

Clears the current offset clause.

Source

pub fn lock_for_update(self) -> LockedQuery

Adds for update.

Source

pub fn shared_lock(self) -> LockedQuery

Adds the dialect’s shared-row lock clause.

Source

pub fn with<C>(self, ctes: C) -> Query
where C: IntoCtes,

Attaches a common table expression.

Source

pub fn with_recursive<C>(self, ctes: C) -> Query
where C: IntoCtes,

Attaches a recursive common table expression.

Source

pub fn scalar<T>(self) -> Scalar<T>
where T: TypeMeta,

Treats the query as a scalar subquery of the requested type.

Source

pub fn distinct(self) -> Query

Emits select distinct.

Source

pub fn not_distinct(self) -> Query

Clears the distinct flag.

Source

pub fn typed<M>(self) -> QueryOf<M>
where M: FromRow,

Attaches a row type once the result shape is known.

Source

pub fn typed_locked<M>(self) -> LockedQueryOf<M>
where M: FromRow,

Source

pub fn to_sql<D>(&mut self) -> String
where D: HasDialect,

Emits SQL for the requested dialect.

Source

pub fn into_compiled<D>(self) -> Compiled
where D: HasDialect,

Compiles the query into an untyped executable payload.

Source

pub fn to_debug_sql<D>(&mut self) -> String
where D: HasDialect,

Emits SQL followed by a debug view of the current parameters.

Source§

impl Query

Source

pub async fn fetch<'e, E>( self, exec: &'e mut E, ) -> Result<<E as Executor>::Rows<'e>, Error>
where E: Executor + ?Sized,

Source

pub async fn all<T>(self, exec: impl Executor) -> Result<Vec<T>, Error>
where T: FromRow,

Source

pub async fn one<T>(self, exec: impl Executor) -> Result<T, Error>
where T: FromRow,

Source

pub async fn optional<T>(self, exec: impl Executor) -> Result<Option<T>, Error>
where T: FromRow,

Source

pub async fn count<E>(self, exec: E) -> Result<i64, Error>
where E: Executor,

Trait Implementations§

Source§

impl Alias for Query

Source§

fn alias(self, alias: &'static str) -> Aliased<Self>
where Self: Sized,

Returns the same value tagged with the provided alias.
Source§

impl Clone for Query

Source§

fn clone(&self) -> Query

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Query

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl From<LockedQuery> for Query

Source§

fn from(value: LockedQuery) -> Query

Converts to this type from the input type.
Source§

impl<M> From<LockedQueryOf<M>> for Query

Source§

fn from(value: LockedQueryOf<M>) -> Query

Converts to this type from the input type.
Source§

impl<M> From<Query> for QueryOf<M>
where M: FromRow,

Source§

fn from(value: Query) -> QueryOf<M>

Converts to this type from the input type.
Source§

impl<M> From<QueryOf<M>> for Query

Source§

fn from(value: QueryOf<M>) -> Query

Converts to this type from the input type.
Source§

impl IntoInsertSelectQuery for Query

Auto Trait Implementations§

§

impl Freeze for Query

§

impl RefUnwindSafe for Query

§

impl Send for Query

§

impl Sync for Query

§

impl Unpin for Query

§

impl UnsafeUnpin for Query

§

impl UnwindSafe for Query

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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<Key> RelationForeignKey<Key> for Key

Source§

fn from_relation_key(key: Key) -> Key

Source§

impl<Key, T> RelationForeignKeyRef<Key> for T
where Key: Clone, T: RelationForeignKey<Key>,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.