Skip to main content

SelectBuilder

Type Alias SelectBuilder 

Source
pub type SelectBuilder<'a, Schema, State, Table = (), Marker = (), Row = (), Grouped = ()> = QueryBuilder<'a, Schema, State, Table, Marker, Row, Grouped>;
Expand description

Builds a SELECT query specifically for PostgreSQL

Aliased Type§

pub struct SelectBuilder<'a, Schema, State, Table = (), Marker = (), Row = (), Grouped = ()> {
    pub sql: SQL<'a, PostgresValue<'a>>,
    /* private fields */
}

Fields§

§sql: SQL<'a, PostgresValue<'a>>

Implementations§

Source§

impl<'a, S, M> SelectBuilder<'a, S, SelectInitial, (), M>

Source

pub fn from<T>( self, query: T, ) -> SelectBuilder<'a, S, SelectFromSet, T, Scoped<M, Cons<T, Nil>>, <M as ResolveRow<T>>::Row>
where T: ToSQL<'a, PostgresValue<'a>>, M: ResolveRow<T>,

Specifies the table to select FROM and transitions state.

Source§

impl<'a, S, State, T, M, R, G> SelectBuilder<'a, S, State, T, M, R, G>
where State: JoinAllowed,

Source

pub fn join<J: JoinArg<'a, T>>( self, arg: J, ) -> SelectBuilder<'a, S, SelectJoinSet, J::JoinedTable, <M as ScopePush<J::JoinedTable>>::Out, <M as AfterJoin<R, J::JoinedTable>>::NewRow, G>

Adds an INNER JOIN clause to the query.

Source

pub fn natural_join<J: JoinSource<'a>>( self, source: J, ) -> SelectBuilder<'a, S, SelectJoinSet, J::JoinedTable, <M as ScopePush<J::JoinedTable>>::Out, <M as AfterJoin<R, J::JoinedTable>>::NewRow, G>
where M: AfterJoin<R, J::JoinedTable> + ScopePush<J::JoinedTable>,

Adds a NATURAL join. The database matches the columns both sides share by name, so it takes a source and no ON condition.

Source

pub fn natural_left_join<J: JoinSource<'a>>( self, source: J, ) -> SelectBuilder<'a, S, SelectJoinSet, J::JoinedTable, <M as ScopePush<J::JoinedTable>>::Out, <M as AfterLeftJoin<R, J::JoinedTable>>::NewRow, G>
where M: AfterLeftJoin<R, J::JoinedTable> + ScopePush<J::JoinedTable>,

Adds a NATURAL join. The database matches the columns both sides share by name, so it takes a source and no ON condition.

Source

pub fn left_join<J: JoinArg<'a, T>>( self, arg: J, ) -> SelectBuilder<'a, S, SelectJoinSet, J::JoinedTable, <M as ScopePush<J::JoinedTable>>::Out, <M as AfterLeftJoin<R, J::JoinedTable>>::NewRow, G>

JOIN with ON clause

Source

pub fn left_outer_join<J: JoinArg<'a, T>>( self, arg: J, ) -> SelectBuilder<'a, S, SelectJoinSet, J::JoinedTable, <M as ScopePush<J::JoinedTable>>::Out, <M as AfterLeftJoin<R, J::JoinedTable>>::NewRow, G>

JOIN with ON clause

Source

pub fn natural_left_outer_join<J: JoinSource<'a>>( self, source: J, ) -> SelectBuilder<'a, S, SelectJoinSet, J::JoinedTable, <M as ScopePush<J::JoinedTable>>::Out, <M as AfterLeftJoin<R, J::JoinedTable>>::NewRow, G>
where M: AfterLeftJoin<R, J::JoinedTable> + ScopePush<J::JoinedTable>,

Adds a NATURAL join. The database matches the columns both sides share by name, so it takes a source and no ON condition.

Source

pub fn natural_right_join<J: JoinSource<'a>>( self, source: J, ) -> SelectBuilder<'a, S, SelectJoinSet, J::JoinedTable, <M as ScopePush<J::JoinedTable>>::Out, <M as AfterRightJoin<R, J::JoinedTable>>::NewRow, G>
where M: AfterRightJoin<R, J::JoinedTable> + ScopePush<J::JoinedTable>,

Adds a NATURAL join. The database matches the columns both sides share by name, so it takes a source and no ON condition.

Source

pub fn right_join<J: JoinArg<'a, T>>( self, arg: J, ) -> SelectBuilder<'a, S, SelectJoinSet, J::JoinedTable, <M as ScopePush<J::JoinedTable>>::Out, <M as AfterRightJoin<R, J::JoinedTable>>::NewRow, G>

JOIN with ON clause

Source

pub fn right_outer_join<J: JoinArg<'a, T>>( self, arg: J, ) -> SelectBuilder<'a, S, SelectJoinSet, J::JoinedTable, <M as ScopePush<J::JoinedTable>>::Out, <M as AfterRightJoin<R, J::JoinedTable>>::NewRow, G>

JOIN with ON clause

Source

pub fn natural_right_outer_join<J: JoinSource<'a>>( self, source: J, ) -> SelectBuilder<'a, S, SelectJoinSet, J::JoinedTable, <M as ScopePush<J::JoinedTable>>::Out, <M as AfterRightJoin<R, J::JoinedTable>>::NewRow, G>
where M: AfterRightJoin<R, J::JoinedTable> + ScopePush<J::JoinedTable>,

Adds a NATURAL join. The database matches the columns both sides share by name, so it takes a source and no ON condition.

Source

pub fn natural_full_join<J: JoinSource<'a>>( self, source: J, ) -> SelectBuilder<'a, S, SelectJoinSet, J::JoinedTable, <M as ScopePush<J::JoinedTable>>::Out, <M as AfterFullJoin<R, J::JoinedTable>>::NewRow, G>
where M: AfterFullJoin<R, J::JoinedTable> + ScopePush<J::JoinedTable>,

Adds a NATURAL join. The database matches the columns both sides share by name, so it takes a source and no ON condition.

Source

pub fn full_join<J: JoinArg<'a, T>>( self, arg: J, ) -> SelectBuilder<'a, S, SelectJoinSet, J::JoinedTable, <M as ScopePush<J::JoinedTable>>::Out, <M as AfterFullJoin<R, J::JoinedTable>>::NewRow, G>

JOIN with ON clause

Source

pub fn full_outer_join<J: JoinArg<'a, T>>( self, arg: J, ) -> SelectBuilder<'a, S, SelectJoinSet, J::JoinedTable, <M as ScopePush<J::JoinedTable>>::Out, <M as AfterFullJoin<R, J::JoinedTable>>::NewRow, G>

JOIN with ON clause

Source

pub fn natural_full_outer_join<J: JoinSource<'a>>( self, source: J, ) -> SelectBuilder<'a, S, SelectJoinSet, J::JoinedTable, <M as ScopePush<J::JoinedTable>>::Out, <M as AfterFullJoin<R, J::JoinedTable>>::NewRow, G>
where M: AfterFullJoin<R, J::JoinedTable> + ScopePush<J::JoinedTable>,

Adds a NATURAL join. The database matches the columns both sides share by name, so it takes a source and no ON condition.

Source

pub fn inner_join<J: JoinArg<'a, T>>( self, arg: J, ) -> SelectBuilder<'a, S, SelectJoinSet, J::JoinedTable, <M as ScopePush<J::JoinedTable>>::Out, <M as AfterJoin<R, J::JoinedTable>>::NewRow, G>

JOIN with ON clause

Source

pub fn left_join_using<U: PostgresTable<'a>>( self, table: U, columns: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, U, <M as ScopePush<U>>::Out, <M as AfterLeftJoin<R, U>>::NewRow, G>
where M: AfterLeftJoin<R, U> + ScopePush<U>,

JOIN with USING clause (PostgreSQL-specific)

Source

pub fn left_outer_join_using<U: PostgresTable<'a>>( self, table: U, columns: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, U, <M as ScopePush<U>>::Out, <M as AfterLeftJoin<R, U>>::NewRow, G>
where M: AfterLeftJoin<R, U> + ScopePush<U>,

JOIN with USING clause (PostgreSQL-specific)

Source

pub fn right_join_using<U: PostgresTable<'a>>( self, table: U, columns: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, U, <M as ScopePush<U>>::Out, <M as AfterRightJoin<R, U>>::NewRow, G>
where M: AfterRightJoin<R, U> + ScopePush<U>,

JOIN with USING clause (PostgreSQL-specific)

Source

pub fn right_outer_join_using<U: PostgresTable<'a>>( self, table: U, columns: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, U, <M as ScopePush<U>>::Out, <M as AfterRightJoin<R, U>>::NewRow, G>
where M: AfterRightJoin<R, U> + ScopePush<U>,

JOIN with USING clause (PostgreSQL-specific)

Source

pub fn full_join_using<U: PostgresTable<'a>>( self, table: U, columns: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, U, <M as ScopePush<U>>::Out, <M as AfterFullJoin<R, U>>::NewRow, G>
where M: AfterFullJoin<R, U> + ScopePush<U>,

JOIN with USING clause (PostgreSQL-specific)

Source

pub fn full_outer_join_using<U: PostgresTable<'a>>( self, table: U, columns: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, U, <M as ScopePush<U>>::Out, <M as AfterFullJoin<R, U>>::NewRow, G>
where M: AfterFullJoin<R, U> + ScopePush<U>,

JOIN with USING clause (PostgreSQL-specific)

Source

pub fn inner_join_using<U: PostgresTable<'a>>( self, table: U, columns: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, U, <M as ScopePush<U>>::Out, <M as AfterJoin<R, U>>::NewRow, G>
where M: AfterJoin<R, U> + ScopePush<U>,

JOIN with USING clause (PostgreSQL-specific)

Source

pub fn join_using<U: PostgresTable<'a>>( self, table: U, columns: impl ToSQL<'a, PostgresValue<'a>>, ) -> SelectBuilder<'a, S, SelectJoinSet, U, <M as ScopePush<U>>::Out, <M as AfterJoin<R, U>>::NewRow, G>
where M: AfterJoin<R, U> + ScopePush<U>,

JOIN with USING clause (PostgreSQL-specific)

Source

pub fn cross_join<Arg: CrossJoinArg<'a, T>>( self, arg: Arg, ) -> SelectBuilder<'a, S, SelectJoinSet, Arg::JoinedTable, <M as ScopePush<Arg::JoinedTable>>::Out, <M as AfterJoin<R, Arg::JoinedTable>>::NewRow, G>
where M: AfterJoin<R, Arg::JoinedTable> + ScopePush<Arg::JoinedTable>,

Adds a cross join.

A bare source renders CROSS JOIN. For backwards compatibility, (source, predicate) renders the equivalent INNER JOIN ... ON ....

Source

pub fn inner_join_lateral<J>( self, arg: J, ) -> SelectBuilder<'a, S, SelectJoinSet, J::JoinedTable, <M as ScopePush<J::JoinedTable>>::Out, <M as AfterJoin<R, J::JoinedTable>>::NewRow, G>
where J: LateralArg<'a, PostgresValue<'a>>, M: AfterJoin<R, J::JoinedTable> + ScopePush<J::JoinedTable>,

Adds an INNER JOIN LATERAL clause.

Source

pub fn left_join_lateral<J, SelectionProof>( self, arg: J, ) -> SelectBuilder<'a, S, SelectJoinSet, J::JoinedTable, <M as ScopePush<J::JoinedTable>>::Out, <M as AfterLeftJoin<R, J::JoinedTable>>::NewRow, G>
where J: LateralArg<'a, PostgresValue<'a>>, M: AfterLeftJoin<R, J::JoinedTable> + ScopePush<J::JoinedTable> + LeftLateralSelection<SelectionProof>,

Adds a LEFT JOIN LATERAL clause.

Source

pub fn cross_join_lateral<Source>( self, source: Source, ) -> SelectBuilder<'a, S, SelectJoinSet, Source::JoinedTable, <M as ScopePush<Source::JoinedTable>>::Out, <M as AfterJoin<R, Source::JoinedTable>>::NewRow, G>
where Source: LateralSource<'a, PostgresValue<'a>>, M: AfterJoin<R, Source::JoinedTable> + ScopePush<Source::JoinedTable>,

Adds a CROSS JOIN LATERAL clause without an ON condition.

Source§

impl<'a, S, State, T, M, R, G> SelectBuilder<'a, S, State, T, M, R, G>
where State: SelectWhereAllowed,

Source

pub fn where<E>( self, condition: E, ) -> SelectBuilder<'a, S, SelectWhereSet, T, M, R, G>
where E: Expr<'a, PostgresValue<'a>>, E::SQLType: BooleanLike,

Adds a WHERE clause to filter query results.

Source§

impl<'a, S, State, T, M, R, G> SelectBuilder<'a, S, State, T, M, R, G>
where State: GroupByAllowed,

Source

pub fn group_by<Gr>( self, columns: Gr, ) -> SelectBuilder<'a, S, SelectGroupSet, T, M, R, Gr::Columns>
where Gr: IntoGroupBy<'a, PostgresValue<'a>>,

Adds a GROUP BY clause to the query.

Non-aggregate columns in SELECT must appear in the GROUP BY list, with one exception: grouping by a table’s single-column primary key functionally determines the whole row (SQL:1999, which PostgreSQL implements natively), so any scalar column of that table may be selected without being listed.

Source§

impl<'a, S, State, T, M, R, G> SelectBuilder<'a, S, State, T, M, R, G>
where State: HavingAllowed,

Source

pub fn having<E>( self, condition: E, ) -> SelectBuilder<'a, S, SelectGroupSet, T, M, R, G>
where E: Expr<'a, PostgresValue<'a>>, E::SQLType: BooleanLike,

Adds a HAVING clause after GROUP BY.

Source§

impl<'a, S, State, T, M, R, G> SelectBuilder<'a, S, State, T, M, R, G>
where State: SelectOrderAllowed,

Source

pub fn order_by<TOrderBy>( self, expressions: TOrderBy, ) -> SelectBuilder<'a, S, SelectOrderSet, T, M, R, G>
where TOrderBy: ToSQL<'a, PostgresValue<'a>>,

Sorts the query results.

Source§

impl<'a, S, T, M, R, G> SelectBuilder<'a, S, SelectSetOpSet, T, M, R, G>

Source

pub fn order_by<TOrderBy>( self, expressions: TOrderBy, ) -> SelectBuilder<'a, S, SelectOrderSet, T, M, R, G>
where TOrderBy: ToSQL<'a, PostgresValue<'a>>,

Sorts a compound (UNION / INTERSECT / EXCEPT) result by its output columns. Column references are rendered unqualified, which is the only spelling PostgreSQL and turso accept here.

Source§

impl<'a, S, State, T, M, R, G> SelectBuilder<'a, S, State, T, M, R, G>
where State: LimitAllowed,

Source

pub fn limit<P>( self, limit: P, ) -> SelectBuilder<'a, S, SelectLimitSet, T, M, R, G>
where P: PaginationArg<'a, PostgresValue<'a>>,

Limits the number of rows returned.

§Panics

Panics when a signed numeric argument is negative or a numeric value does not fit in usize.

Source§

impl<'a, S, State, T, M, R, G> SelectBuilder<'a, S, State, T, M, R, G>
where State: OffsetAllowed,

Source

pub fn offset<P>( self, offset: P, ) -> SelectBuilder<'a, S, SelectOffsetSet, T, M, R, G>
where P: PaginationArg<'a, PostgresValue<'a>>,

Sets the offset for the query results.

§Panics

Panics when a signed numeric argument is negative or a numeric value does not fit in usize.

Source§

impl<'a, S, State, T, M, R, G> SelectBuilder<'a, S, State, T, M, R, G>
where State: ExecutableState,

Source

pub fn alias<Tag, ScopeProof, AggProof>( self, _tag: Tag, ) -> Derived<'a, PostgresValue<'a>, Tag, <M as DerivedSelection<'a, PostgresValue<'a>, PostgresSchemaType, T>>::Projection, Self>
where Tag: Tag, M: DerivedSelection<'a, PostgresValue<'a>, PostgresSchemaType, T> + MarkerScopeValidFor<ScopeProof> + MarkerAggValidFor<G, AggProof>, <M as DerivedSelection<'a, PostgresValue<'a>, PostgresSchemaType, T>>::Projection: DerivedProjection<Tag>,

Names this completed projection for use as a derived table.

§Panics

Panics when the projection contains duplicate output names. Name a computed expression with drizzle_core::expr::NamedExt::named to make each output unique.

Source§

impl<'a, S, State, T, M, R, G> SelectBuilder<'a, S, State, T, M, R, G>
where State: AsCteState, T: SQLTable<'a, PostgresSchemaType, PostgresValue<'a>>,

Source

pub fn into_cte<Tag: Tag + 'static>( self, ) -> CTEView<'a, <T as SQLTable<'a, PostgresSchemaType, PostgresValue<'a>>>::Aliased<Tag>, Self>

Converts this SELECT query into a typed CTE using alias tag name.

Source§

impl<'a, S, State, T, M, R, G> SelectBuilder<'a, S, State, T, M, R, G>
where State: ExecutableState,

Source

pub fn union( self, other: impl IntoSelect<'a, S, M, R>, ) -> SelectBuilder<'a, S, SelectSetOpSet, T, M, R, G>

Combines this query with another using UNION.

Source

pub fn union_all( self, other: impl IntoSelect<'a, S, M, R>, ) -> SelectBuilder<'a, S, SelectSetOpSet, T, M, R, G>

Combines this query with another using UNION ALL.

Source

pub fn intersect( self, other: impl IntoSelect<'a, S, M, R>, ) -> SelectBuilder<'a, S, SelectSetOpSet, T, M, R, G>

Combines this query with another using INTERSECT.

Source

pub fn intersect_all( self, other: impl IntoSelect<'a, S, M, R>, ) -> SelectBuilder<'a, S, SelectSetOpSet, T, M, R, G>

Combines this query with another using INTERSECT ALL.

Source

pub fn except( self, other: impl IntoSelect<'a, S, M, R>, ) -> SelectBuilder<'a, S, SelectSetOpSet, T, M, R, G>

Combines this query with another using EXCEPT.

Source

pub fn except_all( self, other: impl IntoSelect<'a, S, M, R>, ) -> SelectBuilder<'a, S, SelectSetOpSet, T, M, R, G>

Combines this query with another using EXCEPT ALL.

Source§

impl<'a, S, State, T, M, R, G> SelectBuilder<'a, S, State, T, M, R, G>
where State: ForLockableState,

Source

pub fn for_update(self) -> SelectBuilder<'a, S, SelectForSet, T, M, R, G>

Adds FOR UPDATE clause to lock selected rows for update.

Source

pub fn for_share(self) -> SelectBuilder<'a, S, SelectForSet, T, M, R, G>

Adds FOR SHARE clause to lock selected rows for shared access.

Source

pub fn for_no_key_update(self) -> SelectBuilder<'a, S, SelectForSet, T, M, R, G>

Adds FOR NO KEY UPDATE clause.

Source

pub fn for_key_share(self) -> SelectBuilder<'a, S, SelectForSet, T, M, R, G>

Adds FOR KEY SHARE clause.

Source

pub fn for_update_of<U: PostgresTable<'a>>( self, table: U, ) -> SelectBuilder<'a, S, SelectForSet, T, M, R, G>

Adds FOR UPDATE OF table clause.

Source

pub fn for_share_of<U: PostgresTable<'a>>( self, table: U, ) -> SelectBuilder<'a, S, SelectForSet, T, M, R, G>

Adds FOR SHARE OF table clause.

Source§

impl<S, T, M, R, G> SelectBuilder<'_, S, SelectForSet, T, M, R, G>

Source

pub fn nowait(self) -> Self

Adds NOWAIT option to fail immediately if rows are locked.

Source

pub fn skip_locked(self) -> Self

Adds SKIP LOCKED option to skip over locked rows.

Trait Implementations§

Source§

impl<'a, S, State, T, M, R, G> Expr<'a, PostgresValue<'a>> for SelectBuilder<'a, S, State, T, M, R, G>
where State: ExecutableState, M: SubqueryType<'a, PostgresValue<'a>>,

Source§

type SQLType = <M as SubqueryType<'a, PostgresValue<'a>>>::SQLType

The SQL data type this expression evaluates to.
Source§

type Nullable = Null

Whether this expression can be NULL.
Source§

type Aggregate = Scalar

Whether this is an aggregate (COUNT, SUM) or scalar expression.
Source§

fn to_expr_sql(&self) -> SQL<'a, V>

Render this value as a scalar expression by reference. Read more
Source§

fn into_expr_sql(self) -> SQL<'a, V>
where Self: Sized,

Render this value as a scalar expression, consuming it when useful.
Source§

fn to_condition_sql(&self) -> Option<SQL<'a, V>>

Render this value as one element of a ConditionList. Read more
Source§

fn into_condition_sql(self) -> Option<SQL<'a, V>>
where Self: Sized,

Consuming counterpart of Expr::to_condition_sql.
Source§

impl<'a, S, State: ExecutableState, T, M, R, G> IntoSelect<'a, S, M, R> for SelectBuilder<'a, S, State, T, M, R, G>

Source§

type State = State

Source§

type Table = T

Source§

fn into_select(self) -> SelectBuilder<'a, S, State, T, M, R>