diesel::query_source

Struct Alias

Source
#[non_exhaustive]
pub struct Alias<S> { pub source: S, }
Expand description

Represents an alias within diesel’s query builder

See alias! for more details.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§source: S

The inner alias definition

Implementations§

Source§

impl<S: AliasSource> Alias<S>

Source

pub fn field<F>(&self, field: F) -> AliasedField<S, F>
where F: Column<Table = S::Target>,

Maps a single field of the source table in this alias

Source

pub fn fields<Fields>(&self, fields: Fields) -> AliasedFields<S, Fields>
where Fields: FieldAliasMapper<S>,

Maps multiple fields of the source table in this alias (takes in tuples and some expressions)

Trait Implementations§

Source§

impl<S, QS> AppearsInFromClause<QS> for Alias<S>
where S: AliasSource, S::Target: AliasAppearsInFromClause<S, QS>,

Source§

type Count = <<S as AliasSource>::Target as AliasAppearsInFromClause<S, QS>>::Count

How many times does Self appear in QS?
Source§

impl<S> AsQuery for Alias<S>

Source§

type SqlType = <<Alias<S> as QuerySource>::DefaultSelection as Expression>::SqlType

The SQL type of Self::Query
Source§

type Query = SelectStatement<FromClause<Alias<S>>>

What kind of query does this type represent?
Source§

fn as_query(self) -> Self::Query

Converts a type which semantically represents a SQL query into the actual query being executed. See the trait level docs for more.
Source§

impl<'a, S, DB> BoxedDsl<'a, DB> for Alias<S>

Source§

type Output = <SelectStatement<FromClause<Alias<S>>> as BoxedDsl<'a, DB>>::Output

The return type of internal_into_boxed
Source§

fn internal_into_boxed(self) -> Self::Output

See the trait documentation.
Source§

impl<S: Clone> Clone for Alias<S>

Source§

fn clone(&self) -> Alias<S>

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<S> CombineDsl for Alias<S>
where S: AliasSource, S::Target: Table, Self: AsQuery,

Source§

type Query = <Alias<S> as AsQuery>::Query

What kind of query does this type represent?
Source§

fn union<Rhs>(self, rhs: Rhs) -> Union<Self, Rhs>
where Rhs: AsQuery<SqlType = <<Self as AsQuery>::Query as Query>::SqlType>,

Combine two queries using a SQL UNION Read more
Source§

fn union_all<Rhs>(self, rhs: Rhs) -> UnionAll<Self, Rhs>
where Rhs: AsQuery<SqlType = <<Self as AsQuery>::Query as Query>::SqlType>,

Combine two queries using a SQL UNION ALL
Source§

fn intersect<Rhs>(self, rhs: Rhs) -> Intersect<Self, Rhs>
where Rhs: AsQuery<SqlType = <<Self as AsQuery>::Query as Query>::SqlType>,

Combine two queries using a SQL INTERSECT
Source§

fn intersect_all<Rhs>(self, rhs: Rhs) -> IntersectAll<Self, Rhs>
where Rhs: AsQuery<SqlType = <<Self as AsQuery>::Query as Query>::SqlType>,

Combine two queries using a SQL INTERSECT ALL
Source§

fn except<Rhs>(self, rhs: Rhs) -> Except<Self, Rhs>
where Rhs: AsQuery<SqlType = <<Self as AsQuery>::Query as Query>::SqlType>,

Combine two queries using a SQL EXCEPT
Source§

fn except_all<Rhs>(self, rhs: Rhs) -> ExceptAll<Self, Rhs>
where Rhs: AsQuery<SqlType = <<Self as AsQuery>::Query as Query>::SqlType>,

Combine two queries using a SQL EXCEPT ALL
Source§

impl<S: Debug> Debug for Alias<S>

Source§

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

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

impl<S: Default> Default for Alias<S>

Source§

fn default() -> Alias<S>

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

impl<S, Selection> DistinctOnDsl<Selection> for Alias<S>
where S: AliasSource, Selection: SelectableExpression<Self>, Self: QuerySource + AsQuery<Query = SelectStatement<FromClause<Self>>>, SelectStatement<FromClause<Self>>: DistinctOnDsl<Selection>, <Self as QuerySource>::DefaultSelection: Expression<SqlType = <Self as AsQuery>::SqlType> + ValidGrouping<()>, <Self as AsQuery>::SqlType: TypedExpressionType,

Available on crate feature postgres_backend only.
Source§

type Output = <SelectStatement<FromClause<Alias<S>>> as DistinctOnDsl<Selection>>::Output

The type returned by .distinct_on
Source§

fn distinct_on(self, selection: Selection) -> DistinctOn<Self, Selection>

See the trait documentation
Source§

impl<S, Predicate> FilterDsl<Predicate> for Alias<S>
where Self: AsQuery, <Self as AsQuery>::Query: FilterDsl<Predicate>,

Source§

type Output = <<Alias<S> as AsQuery>::Query as FilterDsl<Predicate>>::Output

The type returned by .filter.
Source§

fn filter(self, predicate: Predicate) -> Self::Output

See the trait documentation.
Source§

impl<S, PK> FindDsl<PK> for Alias<S>
where S: AliasSource, S::Target: Table, <S::Target as Table>::PrimaryKey: FieldAliasMapper<S>, <<S::Target as Table>::PrimaryKey as FieldAliasMapper<S>>::Out: EqAll<PK>, Self: FilterDsl<<<<S::Target as Table>::PrimaryKey as FieldAliasMapper<S>>::Out as EqAll<PK>>::Output>,

Source§

type Output = <Alias<S> as FilterDsl<<<<<S as AliasSource>::Target as Table>::PrimaryKey as FieldAliasMapper<S>>::Out as EqAll<PK>>::Output>>::Output

The type returned by .find.
Source§

fn find(self, id: PK) -> Self::Output

See the trait documentation.
Source§

impl<S, Expr> GroupByDsl<Expr> for Alias<S>
where Expr: Expression, Self: QuerySource + AsQuery<Query = SelectStatement<FromClause<Self>>>, <Self as QuerySource>::DefaultSelection: Expression<SqlType = <Self as AsQuery>::SqlType> + ValidGrouping<()>, <Self as AsQuery>::SqlType: TypedExpressionType, <Self as AsQuery>::Query: GroupByDsl<Expr>,

Source§

type Output = <SelectStatement<FromClause<Alias<S>>> as GroupByDsl<Expr>>::Output

The type returned by .group_by
Source§

fn group_by(self, expr: Expr) -> GroupBy<Self, Expr>

See the trait documentation.
Source§

impl<S> LimitDsl for Alias<S>
where Self: AsQuery, <Self as AsQuery>::Query: LimitDsl,

Source§

type Output = <<Alias<S> as AsQuery>::Query as LimitDsl>::Output

The type returned by .limit
Source§

fn limit(self, limit: i64) -> Self::Output

See the trait documentation
Source§

impl<S, Lock> LockingDsl<Lock> for Alias<S>
where Self: QuerySource + AsQuery<Query = SelectStatement<FromClause<Self>>>, <Self as QuerySource>::DefaultSelection: Expression<SqlType = <Self as AsQuery>::SqlType> + ValidGrouping<()>, <Self as AsQuery>::SqlType: TypedExpressionType,

Source§

type Output = <SelectStatement<FromClause<Alias<S>>> as LockingDsl<Lock>>::Output

The type returned by set_lock. See dsl::ForUpdate and friends for convenient access to this type.
Source§

fn with_lock(self, lock: Lock) -> Self::Output

See the trait level documentation
Source§

impl<S> OffsetDsl for Alias<S>
where Self: AsQuery, <Self as AsQuery>::Query: OffsetDsl,

Source§

type Output = <<Alias<S> as AsQuery>::Query as OffsetDsl>::Output

The type returned by .offset.
Source§

fn offset(self, offset: i64) -> Self::Output

See the trait documentation
Source§

impl<S, Predicate> OrFilterDsl<Predicate> for Alias<S>
where Self: AsQuery, <Self as AsQuery>::Query: OrFilterDsl<Predicate>,

Source§

type Output = <<Alias<S> as AsQuery>::Query as OrFilterDsl<Predicate>>::Output

The type returned by .filter.
Source§

fn or_filter(self, predicate: Predicate) -> Self::Output

See the trait documentation.
Source§

impl<S, Expr> OrderDsl<Expr> for Alias<S>
where Expr: Expression, Self: AsQuery, <Self as AsQuery>::Query: OrderDsl<Expr>,

Source§

type Output = <<Alias<S> as AsQuery>::Query as OrderDsl<Expr>>::Output

The type returned by .order.
Source§

fn order(self, expr: Expr) -> Self::Output

See the trait documentation.
Source§

impl<S: AliasSource> QueryDsl for Alias<S>

Source§

fn distinct_on<Expr>(self, expr: Expr) -> DistinctOn<Self, Expr>
where Self: DistinctOnDsl<Expr>,

Available on crate feature postgres_backend only.
Adds the DISTINCT ON clause to a query. Read more
Source§

fn select<Selection>(self, selection: Selection) -> Select<Self, Selection>
where Selection: Expression, Self: SelectDsl<Selection>,

Adds a SELECT clause to the query. Read more
Source§

fn count(self) -> Select<Self, CountStar>
where Self: SelectDsl<CountStar>,

Get the count of a query. This is equivalent to .select(count_star()) Read more
Source§

fn inner_join<Rhs>(self, rhs: Rhs) -> InnerJoin<Self, Rhs>
where Self: JoinWithImplicitOnClause<Rhs, Inner>,

Join two tables using a SQL INNER JOIN. Read more
Source§

fn left_outer_join<Rhs>(self, rhs: Rhs) -> LeftJoin<Self, Rhs>
where Self: JoinWithImplicitOnClause<Rhs, LeftOuter>,

Join two tables using a SQL LEFT OUTER JOIN. Read more
Source§

fn left_join<Rhs>(self, rhs: Rhs) -> LeftJoin<Self, Rhs>
where Self: JoinWithImplicitOnClause<Rhs, LeftOuter>,

Alias for left_outer_join.
Source§

fn filter<Predicate>(self, predicate: Predicate) -> Filter<Self, Predicate>
where Self: FilterDsl<Predicate>,

Adds to the WHERE clause of a query. Read more
Source§

fn or_filter<Predicate>(self, predicate: Predicate) -> OrFilter<Self, Predicate>
where Self: OrFilterDsl<Predicate>,

Adds to the WHERE clause of a query using OR Read more
Source§

fn find<PK>(self, id: PK) -> Find<Self, PK>
where Self: FindDsl<PK>,

Attempts to find a single record from the given table by primary key. Read more
Source§

fn order<Expr>(self, expr: Expr) -> Order<Self, Expr>
where Expr: Expression, Self: OrderDsl<Expr>,

Sets the order clause of a query. Read more
Source§

fn order_by<Expr>(self, expr: Expr) -> OrderBy<Self, Expr>
where Expr: Expression, Self: OrderDsl<Expr>,

Alias for order
Source§

fn then_order_by<Order>(self, order: Order) -> ThenOrderBy<Self, Order>
where Self: ThenOrderDsl<Order>,

Appends to the ORDER BY clause of this SQL query. Read more
Source§

fn limit(self, limit: i64) -> Limit<Self>
where Self: LimitDsl,

Sets the limit clause of the query. Read more
Source§

fn offset(self, offset: i64) -> Offset<Self>
where Self: OffsetDsl,

Sets the offset clause of the query. Read more
Source§

fn group_by<GB>(self, group_by: GB) -> GroupBy<Self, GB>
where GB: Expression, Self: GroupByDsl<GB>,

Sets the group by clause of a query. Read more
Source§

fn having<Predicate>(self, predicate: Predicate) -> Having<Self, Predicate>
where Self: HavingDsl<Predicate>,

Adds to the HAVING clause of a query. Read more
Source§

fn for_update(self) -> ForUpdate<Self>
where Self: LockingDsl<ForUpdate>,

Adds FOR UPDATE to the end of the select statement. Read more
Source§

fn for_no_key_update(self) -> ForNoKeyUpdate<Self>
where Self: LockingDsl<ForNoKeyUpdate>,

Adds FOR NO KEY UPDATE to the end of the select statement. Read more
Source§

fn for_share(self) -> ForShare<Self>
where Self: LockingDsl<ForShare>,

Adds FOR SHARE to the end of the select statement. Read more
Source§

fn for_key_share(self) -> ForKeyShare<Self>
where Self: LockingDsl<ForKeyShare>,

Adds FOR KEY SHARE to the end of the select statement. Read more
Source§

fn into_boxed<'a, DB>(self) -> IntoBoxed<'a, Self, DB>
where DB: Backend, Self: BoxedDsl<'a, DB>,

Boxes the pieces of a query into a single type. Read more
Source§

impl<S, DB> QueryFragment<DB> for Alias<S>
where S: AliasSource, DB: Backend, Self: QueryFragment<DB, DB::AliasSyntax>,

Source§

fn walk_ast<'b>(&'b self, pass: AstPass<'_, 'b, DB>) -> QueryResult<()>

Walk over this QueryFragment for all passes. Read more
Source§

fn to_sql(&self, out: &mut DB::QueryBuilder, backend: &DB) -> QueryResult<()>

Available on crate feature i-implement-a-third-party-backend-and-opt-into-breaking-changes only.
Converts this QueryFragment to its SQL representation. Read more
Source§

fn collect_binds<'b>( &'b self, out: &mut DB::BindCollector<'b>, metadata_lookup: &mut DB::MetadataLookup, backend: &'b DB, ) -> QueryResult<()>

Available on crate feature i-implement-a-third-party-backend-and-opt-into-breaking-changes only.
Serializes all bind parameters in this query. Read more
Source§

fn is_safe_to_cache_prepared(&self, backend: &DB) -> QueryResult<bool>

Available on crate feature i-implement-a-third-party-backend-and-opt-into-breaking-changes only.
Is this query safe to store in the prepared statement cache? Read more
Source§

fn is_noop(&self, backend: &DB) -> QueryResult<bool>

Available on crate feature i-implement-a-third-party-backend-and-opt-into-breaking-changes only.
Does walking this AST have any effect?
Source§

impl<S, DB> QueryFragment<DB, AsAliasSyntax> for Alias<S>
where S: AliasSource, DB: Backend, S::Target: QueryFragment<DB>,

Source§

fn walk_ast<'b>(&'b self, pass: AstPass<'_, 'b, DB>) -> QueryResult<()>

Walk over this QueryFragment for all passes. Read more
Source§

fn to_sql(&self, out: &mut DB::QueryBuilder, backend: &DB) -> QueryResult<()>

Available on crate feature i-implement-a-third-party-backend-and-opt-into-breaking-changes only.
Converts this QueryFragment to its SQL representation. Read more
Source§

fn collect_binds<'b>( &'b self, out: &mut DB::BindCollector<'b>, metadata_lookup: &mut DB::MetadataLookup, backend: &'b DB, ) -> QueryResult<()>

Available on crate feature i-implement-a-third-party-backend-and-opt-into-breaking-changes only.
Serializes all bind parameters in this query. Read more
Source§

fn is_safe_to_cache_prepared(&self, backend: &DB) -> QueryResult<bool>

Available on crate feature i-implement-a-third-party-backend-and-opt-into-breaking-changes only.
Is this query safe to store in the prepared statement cache? Read more
Source§

fn is_noop(&self, backend: &DB) -> QueryResult<bool>

Available on crate feature i-implement-a-third-party-backend-and-opt-into-breaking-changes only.
Does walking this AST have any effect?
Source§

impl<S> QueryId for Alias<S>
where Self: 'static, S: AliasSource, S::Target: QueryId,

Source§

const HAS_STATIC_QUERY_ID: bool = <S::Target as QueryId>::HAS_STATIC_QUERY_ID

Can the SQL generated by Self be uniquely identified by its type? Read more
Source§

type QueryId = Alias<S>

A type which uniquely represents Self in a SQL query. Read more
Source§

fn query_id() -> Option<TypeId>

Returns the type id of Self::QueryId if Self::HAS_STATIC_QUERY_ID. Returns None otherwise. Read more
Source§

impl<S> QuerySource for Alias<S>
where Self: Clone, S: AliasSource, S::Target: QuerySource, <S::Target as QuerySource>::DefaultSelection: FieldAliasMapper<S>, <<S::Target as QuerySource>::DefaultSelection as FieldAliasMapper<S>>::Out: SelectableExpression<Self>,

Source§

type FromClause = Alias<S>

The type returned by from_clause
Source§

type DefaultSelection = <<<S as AliasSource>::Target as QuerySource>::DefaultSelection as FieldAliasMapper<S>>::Out

The type returned by default_selection
Source§

fn from_clause(&self) -> Self::FromClause

The actual FROM clause of this type. This is typically only called in QueryFragment implementations.
Source§

fn default_selection(&self) -> Self::DefaultSelection

The default select clause of this type, which should be used if no select clause was explicitly specified. This should always be a tuple of all the desired columns, not star
Source§

impl<S: AliasSource, Conn> RunQueryDsl<Conn> for Alias<S>

Source§

fn execute(self, conn: &mut Conn) -> QueryResult<usize>
where Conn: Connection, Self: ExecuteDsl<Conn>,

Executes the given command, returning the number of rows affected. Read more
Source§

fn load<'query, U>(self, conn: &mut Conn) -> QueryResult<Vec<U>>
where Self: LoadQuery<'query, Conn, U>,

Executes the given query, returning a Vec with the returned rows. Read more
Source§

fn load_iter<'conn, 'query: 'conn, U, B>( self, conn: &'conn mut Conn, ) -> QueryResult<Self::RowIter<'conn>>
where U: 'conn, Self: LoadQuery<'query, Conn, U, B> + 'conn,

Executes the given query, returning an Iterator with the returned rows. Read more
Source§

fn get_result<'query, U>(self, conn: &mut Conn) -> QueryResult<U>
where Self: LoadQuery<'query, Conn, U>,

Runs the command, and returns the affected row. Read more
Source§

fn get_results<'query, U>(self, conn: &mut Conn) -> QueryResult<Vec<U>>
where Self: LoadQuery<'query, Conn, U>,

Runs the command, returning an Vec with the affected rows. Read more
Source§

fn first<'query, U>(self, conn: &mut Conn) -> QueryResult<U>
where Self: LimitDsl, Limit<Self>: LoadQuery<'query, Conn, U>,

Attempts to load a single record. Read more
Source§

impl<S, Selection> SelectDsl<Selection> for Alias<S>
where Selection: Expression, Self: AsQuery, <Self as AsQuery>::Query: SelectDsl<Selection>,

Source§

type Output = <<Alias<S> as AsQuery>::Query as SelectDsl<Selection>>::Output

The type returned by .select
Source§

fn select(self, selection: Selection) -> Self::Output

See the trait documentation
Source§

impl<S, Expr> ThenOrderDsl<Expr> for Alias<S>
where Expr: Expression, Self: AsQuery, <Self as AsQuery>::Query: ThenOrderDsl<Expr>,

Source§

type Output = <<Alias<S> as AsQuery>::Query as ThenOrderDsl<Expr>>::Output

The type returned by .then_order_by.
Source§

fn then_order_by(self, expr: Expr) -> Self::Output

See the trait documentation.
Source§

impl<S: Copy> Copy for Alias<S>

Source§

impl<S2, S> JoinTo<Alias<S2>> for Alias<S>
where S2: AliasSource, S: AliasSource + Default, S::Target: JoinTo<Alias<S2>>, <S::Target as JoinTo<Alias<S2>>>::OnClause: FieldAliasMapper<S>,

Source§

impl<T, S> JoinTo<T> for Alias<S>
where T: Table, S: AliasSource + Default, S::Target: JoinTo<T>, <S::Target as JoinTo<T>>::OnClause: FieldAliasMapper<S>,

Source§

impl<S, C> SelectableExpression<Alias<S>> for AliasedField<S, C>
where S: AliasSource, C: Column<Table = S::Target>, Self: AppearsOnTable<Alias<S>>,

Auto Trait Implementations§

§

impl<S> Freeze for Alias<S>
where S: Freeze,

§

impl<S> RefUnwindSafe for Alias<S>
where S: RefUnwindSafe,

§

impl<S> Send for Alias<S>
where S: Send,

§

impl<S> Sync for Alias<S>
where S: Sync,

§

impl<S> Unpin for Alias<S>
where S: Unpin,

§

impl<S> UnwindSafe for Alias<S>
where S: 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> CloneToUninit for T
where T: Clone,

Source§

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

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

impl<Conn, DB, T> ExecuteDsl<Conn, DB> for T
where Conn: Connection<Backend = DB>, DB: Backend, T: QueryFragment<DB> + QueryId,

Source§

fn execute(query: T, conn: &mut Conn) -> Result<usize, Error>

Execute this command
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<T> IntoSql for T

Source§

fn into_sql<T>(self) -> AsExprOf<Self, T>

Convert self to an expression for Diesel’s query builder. Read more
Source§

fn as_sql<'a, T>(&'a self) -> AsExprOf<&'a Self, T>
where &'a Self: AsExpression<T>, T: SqlType + TypedExpressionType,

Convert &self to an expression for Diesel’s query builder. Read more
Source§

impl<T> JoinOnDsl for T
where T: QuerySource,

Source§

fn on<On>(self, on: On) -> On<Self, On>

See the trait documentation.
Source§

impl<T, DB> QueryFragmentForCachedStatement<DB> for T
where DB: Backend, <DB as Backend>::QueryBuilder: Default, T: QueryFragment<DB>,

Source§

fn construct_sql(&self, backend: &DB) -> Result<String, Error>

Available on crate feature i-implement-a-third-party-backend-and-opt-into-breaking-changes only.
Convert the query fragment into a SQL string for the given backend
Source§

fn is_safe_to_cache_prepared(&self, backend: &DB) -> Result<bool, Error>

Available on crate feature i-implement-a-third-party-backend-and-opt-into-breaking-changes only.
Check whether it’s safe to cache the query
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

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

Source§

impl<T> MaybeSendSync for T