pub struct SelectStatement { /* private fields */ }native and crate feature database only.Expand description
SELECT statement builder
This struct provides a fluent API for constructing SELECT queries.
§Examples
use reinhardt_query::prelude::*;
let query = Query::select()
.column(Expr::col("id"))
.column(Expr::col("name"))
.from("users")
.and_where(Expr::col("active").eq(true))
.order_by("name", Order::Asc)
.limit(10);Implementations§
Source§impl SelectStatement
impl SelectStatement
Sourcepub fn new() -> SelectStatement
pub fn new() -> SelectStatement
Create a new SELECT statement
Sourcepub fn take(&mut self) -> SelectStatement
pub fn take(&mut self) -> SelectStatement
Take the ownership of data in the current SelectStatement
Sourcepub fn column<C>(&mut self, col: C) -> &mut SelectStatementwhere
C: IntoColumnRef,
pub fn column<C>(&mut self, col: C) -> &mut SelectStatementwhere
C: IntoColumnRef,
Sourcepub fn columns<I, C>(&mut self, cols: I) -> &mut SelectStatementwhere
I: IntoIterator<Item = C>,
C: IntoColumnRef,
pub fn columns<I, C>(&mut self, cols: I) -> &mut SelectStatementwhere
I: IntoIterator<Item = C>,
C: IntoColumnRef,
Sourcepub fn expr<E>(&mut self, expr: E) -> &mut SelectStatementwhere
E: Into<SimpleExpr>,
pub fn expr<E>(&mut self, expr: E) -> &mut SelectStatementwhere
E: Into<SimpleExpr>,
Sourcepub fn expr_as<E, A>(&mut self, expr: E, alias: A) -> &mut SelectStatement
pub fn expr_as<E, A>(&mut self, expr: E, alias: A) -> &mut SelectStatement
Sourcepub fn from<T>(&mut self, tbl: T) -> &mut SelectStatementwhere
T: IntoTableRef,
pub fn from<T>(&mut self, tbl: T) -> &mut SelectStatementwhere
T: IntoTableRef,
Sourcepub fn from_as<T, A>(&mut self, tbl: T, alias: A) -> &mut SelectStatement
pub fn from_as<T, A>(&mut self, tbl: T, alias: A) -> &mut SelectStatement
Add a table with alias to the FROM clause
Equivalent to FROM table AS alias.
Sourcepub fn from_subquery(
&mut self,
query: SelectStatement,
alias: impl IntoIden,
) -> &mut SelectStatement
pub fn from_subquery( &mut self, query: SelectStatement, alias: impl IntoIden, ) -> &mut SelectStatement
Add a subquery to the FROM clause
Equivalent to FROM (SELECT ...) AS alias.
Sourcepub fn clear_selects(&mut self) -> &mut SelectStatement
pub fn clear_selects(&mut self) -> &mut SelectStatement
Clear all column selections
Sourcepub fn join<T, C>(
&mut self,
join: JoinType,
tbl: T,
condition: C,
) -> &mut SelectStatementwhere
T: IntoTableRef,
C: IntoCondition,
pub fn join<T, C>(
&mut self,
join: JoinType,
tbl: T,
condition: C,
) -> &mut SelectStatementwhere
T: IntoTableRef,
C: IntoCondition,
Sourcepub fn left_join<T, C>(&mut self, tbl: T, condition: C) -> &mut SelectStatementwhere
T: IntoTableRef,
C: IntoCondition,
pub fn left_join<T, C>(&mut self, tbl: T, condition: C) -> &mut SelectStatementwhere
T: IntoTableRef,
C: IntoCondition,
Sourcepub fn right_join<T, C>(&mut self, tbl: T, condition: C) -> &mut SelectStatementwhere
T: IntoTableRef,
C: IntoCondition,
pub fn right_join<T, C>(&mut self, tbl: T, condition: C) -> &mut SelectStatementwhere
T: IntoTableRef,
C: IntoCondition,
Add a RIGHT JOIN clause
Sourcepub fn full_outer_join<T, C>(
&mut self,
tbl: T,
condition: C,
) -> &mut SelectStatementwhere
T: IntoTableRef,
C: IntoCondition,
pub fn full_outer_join<T, C>(
&mut self,
tbl: T,
condition: C,
) -> &mut SelectStatementwhere
T: IntoTableRef,
C: IntoCondition,
Add a FULL OUTER JOIN clause
Sourcepub fn inner_join<T, C>(&mut self, tbl: T, condition: C) -> &mut SelectStatementwhere
T: IntoTableRef,
C: IntoCondition,
pub fn inner_join<T, C>(&mut self, tbl: T, condition: C) -> &mut SelectStatementwhere
T: IntoTableRef,
C: IntoCondition,
Add an INNER JOIN clause
Sourcepub fn cross_join<T>(&mut self, tbl: T) -> &mut SelectStatementwhere
T: IntoTableRef,
pub fn cross_join<T>(&mut self, tbl: T) -> &mut SelectStatementwhere
T: IntoTableRef,
Add a CROSS JOIN clause
Sourcepub fn and_where<C>(&mut self, condition: C) -> &mut SelectStatementwhere
C: IntoCondition,
pub fn and_where<C>(&mut self, condition: C) -> &mut SelectStatementwhere
C: IntoCondition,
Sourcepub fn cond_where(&mut self, condition: Condition) -> &mut SelectStatement
pub fn cond_where(&mut self, condition: Condition) -> &mut SelectStatement
Add a condition to the WHERE clause using Condition
Sourcepub fn group_by<C>(&mut self, col: C) -> &mut SelectStatementwhere
C: IntoColumnRef,
pub fn group_by<C>(&mut self, col: C) -> &mut SelectStatementwhere
C: IntoColumnRef,
Sourcepub fn group_by_col<C>(&mut self, col: C) -> &mut SelectStatementwhere
C: IntoColumnRef,
pub fn group_by_col<C>(&mut self, col: C) -> &mut SelectStatementwhere
C: IntoColumnRef,
Add a column to the GROUP BY clause (alias for group_by)
Sourcepub fn group_by_columns<I, C>(&mut self, cols: I) -> &mut SelectStatementwhere
I: IntoIterator<Item = C>,
C: IntoColumnRef,
pub fn group_by_columns<I, C>(&mut self, cols: I) -> &mut SelectStatementwhere
I: IntoIterator<Item = C>,
C: IntoColumnRef,
Add multiple GROUP BY columns
Sourcepub fn and_having<C>(&mut self, condition: C) -> &mut SelectStatementwhere
C: IntoCondition,
pub fn and_having<C>(&mut self, condition: C) -> &mut SelectStatementwhere
C: IntoCondition,
Sourcepub fn cond_having(&mut self, condition: Condition) -> &mut SelectStatement
pub fn cond_having(&mut self, condition: Condition) -> &mut SelectStatement
Add a condition to the HAVING clause using Condition
Sourcepub fn order_by<C>(&mut self, col: C, order: Order) -> &mut SelectStatementwhere
C: IntoColumnRef,
pub fn order_by<C>(&mut self, col: C, order: Order) -> &mut SelectStatementwhere
C: IntoColumnRef,
Sourcepub fn order_by_expr<E>(
&mut self,
expr: E,
order: Order,
) -> &mut SelectStatementwhere
E: Into<SimpleExpr>,
pub fn order_by_expr<E>(
&mut self,
expr: E,
order: Order,
) -> &mut SelectStatementwhere
E: Into<SimpleExpr>,
Add an ORDER BY clause with expression
Sourcepub fn limit<V>(&mut self, limit: V) -> &mut SelectStatementwhere
V: IntoValue,
pub fn limit<V>(&mut self, limit: V) -> &mut SelectStatementwhere
V: IntoValue,
Sourcepub fn offset<V>(&mut self, offset: V) -> &mut SelectStatementwhere
V: IntoValue,
pub fn offset<V>(&mut self, offset: V) -> &mut SelectStatementwhere
V: IntoValue,
Sourcepub fn distinct(&mut self) -> &mut SelectStatement
pub fn distinct(&mut self) -> &mut SelectStatement
Sourcepub fn distinct_on<I, C>(&mut self, cols: I) -> &mut SelectStatementwhere
I: IntoIterator<Item = C>,
C: IntoColumnRef,
pub fn distinct_on<I, C>(&mut self, cols: I) -> &mut SelectStatementwhere
I: IntoIterator<Item = C>,
C: IntoColumnRef,
Set DISTINCT ON (PostgreSQL only)
Sourcepub fn union(&mut self, query: SelectStatement) -> &mut SelectStatement
pub fn union(&mut self, query: SelectStatement) -> &mut SelectStatement
Add a UNION clause
Sourcepub fn union_all(&mut self, query: SelectStatement) -> &mut SelectStatement
pub fn union_all(&mut self, query: SelectStatement) -> &mut SelectStatement
Add a UNION ALL clause
Sourcepub fn intersect(&mut self, query: SelectStatement) -> &mut SelectStatement
pub fn intersect(&mut self, query: SelectStatement) -> &mut SelectStatement
Add an INTERSECT clause
Sourcepub fn except(&mut self, query: SelectStatement) -> &mut SelectStatement
pub fn except(&mut self, query: SelectStatement) -> &mut SelectStatement
Add an EXCEPT clause
Sourcepub fn with_cte<N>(
&mut self,
name: N,
query: SelectStatement,
) -> &mut SelectStatementwhere
N: IntoIden,
pub fn with_cte<N>(
&mut self,
name: N,
query: SelectStatement,
) -> &mut SelectStatementwhere
N: IntoIden,
Add a Common Table Expression (CTE) to the WITH clause
§Examples
use reinhardt_query::prelude::*;
let cte = Query::select()
.column("id")
.column("name")
.from("users")
.and_where(Expr::col("active").eq(true));
let query = Query::select()
.with_cte("active_users", cte)
.column("*")
.from("active_users");Sourcepub fn with_recursive_cte<N>(
&mut self,
name: N,
query: SelectStatement,
) -> &mut SelectStatementwhere
N: IntoIden,
pub fn with_recursive_cte<N>(
&mut self,
name: N,
query: SelectStatement,
) -> &mut SelectStatementwhere
N: IntoIden,
Add a RECURSIVE Common Table Expression (CTE) to the WITH clause
§Examples
use reinhardt_query::prelude::*;
// Recursive CTE for hierarchical data
let cte = Query::select()
.column("id")
.column("parent_id")
.column("name")
.from("categories")
.and_where(Expr::col("parent_id").is_null())
.union_all(
Query::select()
.column(Expr::col(("c", "id")))
.column(Expr::col(("c", "parent_id")))
.column(Expr::col(("c", "name")))
.from_as("categories", "c")
.join(
JoinType::InnerJoin,
"category_tree",
Expr::col(("c", "parent_id")).eq(Expr::col(("category_tree", "id")))
)
);
let query = Query::select()
.with_recursive_cte("category_tree", cte)
.column("*")
.from("category_tree");Sourcepub fn window_as<T>(
&mut self,
name: T,
window: WindowStatement,
) -> &mut SelectStatementwhere
T: IntoIden,
pub fn window_as<T>(
&mut self,
name: T,
window: WindowStatement,
) -> &mut SelectStatementwhere
T: IntoIden,
Add a named window specification to the WINDOW clause
Named windows can be referenced by window functions using OVER window_name.
§Examples
use reinhardt_query::prelude::*;
use reinhardt_query::types::window::WindowStatement;
let window = WindowStatement {
partition_by: vec![Expr::col("department_id").into_simple_expr()],
order_by: vec![OrderExpr {
expr: Expr::col("salary").into_simple_expr(),
order: Order::Desc,
nulls: None,
}],
frame: None,
};
let query = Query::select()
.column("name")
.expr_as(Expr::row_number().over_named("w"), "rank")
.from("employees")
.window_as("w", window);Sourcepub fn lock(&mut self, lock_type: LockType) -> &mut SelectStatement
pub fn lock(&mut self, lock_type: LockType) -> &mut SelectStatement
Set FOR UPDATE lock
Sourcepub fn lock_exclusive(&mut self) -> &mut SelectStatement
pub fn lock_exclusive(&mut self) -> &mut SelectStatement
Set FOR UPDATE lock
Set FOR SHARE lock
Sourcepub fn apply_if<T, F>(
&mut self,
val: Option<T>,
func: F,
) -> &mut SelectStatementwhere
F: FnOnce(&mut SelectStatement, T),
pub fn apply_if<T, F>(
&mut self,
val: Option<T>,
func: F,
) -> &mut SelectStatementwhere
F: FnOnce(&mut SelectStatement, T),
Apply a function conditionally
Sourcepub fn conditions<T, F>(
&mut self,
b: bool,
if_true: T,
if_false: F,
) -> &mut SelectStatement
pub fn conditions<T, F>( &mut self, b: bool, if_true: T, if_false: F, ) -> &mut SelectStatement
Conditional execution
Trait Implementations§
Source§impl Clone for SelectStatement
impl Clone for SelectStatement
Source§fn clone(&self) -> SelectStatement
fn clone(&self) -> SelectStatement
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SelectStatement
impl Debug for SelectStatement
Source§impl Default for SelectStatement
impl Default for SelectStatement
Source§fn default() -> SelectStatement
fn default() -> SelectStatement
Source§impl QueryStatementBuilder for SelectStatement
impl QueryStatementBuilder for SelectStatement
Source§fn build_any(
&self,
query_builder: &(dyn QueryBuilderTrait + 'static),
) -> (String, Values)
fn build_any( &self, query_builder: &(dyn QueryBuilderTrait + 'static), ) -> (String, Values)
impl QueryStatementWriter for SelectStatement
Auto Trait Implementations§
impl !RefUnwindSafe for SelectStatement
impl !UnwindSafe for SelectStatement
impl Freeze for SelectStatement
impl Send for SelectStatement
impl Sync for SelectStatement
impl Unpin for SelectStatement
impl UnsafeUnpin for SelectStatement
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> IntoResult<T> for T
impl<T> IntoResult<T> for T
type Err = Infallible
fn into_result(self) -> Result<T, <T as IntoResult<T>>::Err>
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().Source§impl<E> ServerFnErrorAssertions<E> for Ewhere
E: Debug,
impl<E> ServerFnErrorAssertions<E> for Ewhere
E: Debug,
Source§fn should_contain_message(&self, expected: &str)where
E: Display,
fn should_contain_message(&self, expected: &str)where
E: Display,
Source§fn should_have_message(&self, expected: &str)where
E: Display,
fn should_have_message(&self, expected: &str)where
E: Display,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.