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
impl Query
pub fn delete_query(self) -> Delete<()>
pub async fn delete<E>(self, exec: E) -> Result<ExecResult, Error>where
E: Executor,
Source§impl Query
impl Query
Sourcepub fn select<S>(self, s: S) -> Querywhere
S: LowerProject,
pub fn select<S>(self, s: S) -> Querywhere
S: LowerProject,
Replaces the current projection list.
Sourcepub fn reset_select(&mut self)
pub fn reset_select(&mut self)
Clears the current projection list.
Sourcepub fn left_join<J>(self, join: J) -> Querywhere
J: LowerJoin,
pub fn left_join<J>(self, join: J) -> Querywhere
J: LowerJoin,
Adds a left join to the current from clause.
Sourcepub fn right_join<J>(self, join: J) -> Querywhere
J: LowerJoin,
pub fn right_join<J>(self, join: J) -> Querywhere
J: LowerJoin,
Adds a right join to the current from clause.
Sourcepub fn inner_join<J>(self, join: J) -> Querywhere
J: LowerJoin,
pub fn inner_join<J>(self, join: J) -> Querywhere
J: LowerJoin,
Adds an inner join to the current from clause.
Sourcepub fn having<E>(self, e: E) -> Querywhere
E: LowerHaving,
pub fn having<E>(self, e: E) -> Querywhere
E: LowerHaving,
Adds a having predicate combined with and.
Sourcepub fn or_having<E>(self, e: E) -> Querywhere
E: LowerHaving,
pub fn or_having<E>(self, e: E) -> Querywhere
E: LowerHaving,
Adds a having predicate combined with or.
Sourcepub fn filter<E>(self, e: E) -> Querywhere
E: LowerFilter,
pub fn filter<E>(self, e: E) -> Querywhere
E: LowerFilter,
Adds a where predicate combined with and.
Sourcepub fn or_filter<E>(self, e: E) -> Querywhere
E: LowerFilter,
pub fn or_filter<E>(self, e: E) -> Querywhere
E: LowerFilter,
Adds a where predicate combined with or.
Sourcepub fn union(self, other: impl Into<Query>) -> Query
pub fn union(self, other: impl Into<Query>) -> Query
Combines this query with another one using union.
Sourcepub fn union_all(self, other: impl Into<Query>) -> Query
pub fn union_all(self, other: impl Into<Query>) -> Query
Combines this query with another one using union all.
Sourcepub fn group_by<T>(self, by: T) -> Querywhere
T: LowerGroupBy,
pub fn group_by<T>(self, by: T) -> Querywhere
T: LowerGroupBy,
Appends grouping expressions to group by.
Sourcepub fn order_by<T>(self, by: T) -> Querywhere
T: LowerOrderBy,
pub fn order_by<T>(self, by: T) -> Querywhere
T: LowerOrderBy,
Appends ordering expressions to order by.
Sourcepub fn order_by_random(self) -> Query
pub fn order_by_random(self) -> Query
Appends a random ordering expression.
Sourcepub fn limit<E>(self, e: E) -> Querywhere
E: LowerCompatible<BigInt>,
pub fn limit<E>(self, e: E) -> Querywhere
E: LowerCompatible<BigInt>,
Replaces any existing limit clause.
Sourcepub fn reset_limit(&mut self)
pub fn reset_limit(&mut self)
Clears the current limit clause.
Sourcepub fn offset<E>(self, e: E) -> Querywhere
E: LowerCompatible<BigInt>,
pub fn offset<E>(self, e: E) -> Querywhere
E: LowerCompatible<BigInt>,
Replaces any existing offset clause.
Sourcepub fn reset_offset(&mut self)
pub fn reset_offset(&mut self)
Clears the current offset clause.
Sourcepub fn lock_for_update(self) -> LockedQuery
pub fn lock_for_update(self) -> LockedQuery
Adds for update.
Adds the dialect’s shared-row lock clause.
Sourcepub fn with_recursive<C>(self, ctes: C) -> Querywhere
C: IntoCtes,
pub fn with_recursive<C>(self, ctes: C) -> Querywhere
C: IntoCtes,
Attaches a recursive common table expression.
Sourcepub fn scalar<T>(self) -> Scalar<T>where
T: TypeMeta,
pub fn scalar<T>(self) -> Scalar<T>where
T: TypeMeta,
Treats the query as a scalar subquery of the requested type.
Sourcepub fn not_distinct(self) -> Query
pub fn not_distinct(self) -> Query
Clears the distinct flag.
Sourcepub fn typed<M>(self) -> QueryOf<M>where
M: FromRow,
pub fn typed<M>(self) -> QueryOf<M>where
M: FromRow,
Attaches a row type once the result shape is known.
pub fn typed_locked<M>(self) -> LockedQueryOf<M>where
M: FromRow,
Sourcepub fn to_sql<D>(&mut self) -> Stringwhere
D: HasDialect,
pub fn to_sql<D>(&mut self) -> Stringwhere
D: HasDialect,
Emits SQL for the requested dialect.
Sourcepub fn into_compiled<D>(self) -> Compiledwhere
D: HasDialect,
pub fn into_compiled<D>(self) -> Compiledwhere
D: HasDialect,
Compiles the query into an untyped executable payload.
Sourcepub fn to_debug_sql<D>(&mut self) -> Stringwhere
D: HasDialect,
pub fn to_debug_sql<D>(&mut self) -> Stringwhere
D: HasDialect,
Emits SQL followed by a debug view of the current parameters.