Skip to main content

SelectQuery

Struct SelectQuery 

Source
pub struct SelectQuery {
Show 14 fields pub with: With, pub distinct: bool, pub select_list: SelectList, pub values: Values, pub from: TableRef, pub extra_from: Vec<TableRef>, pub where_: Where, pub group_by: GroupBy, pub having: Having, pub windows: Windows, pub compounds: Compounds, pub order_by: OrderBy, pub limit: Limit, pub offset: Offset,
}
Expand description

A SQLite SELECT.

The field order is the clause order of https://www.sqlite.org/lang_select.html:

[ WITH [ RECURSIVE ] common-table-expression [, ...] ]
select-core [ compound-operator select-core ]*
[ ORDER BY ordering-term [, ...] ]
[ LIMIT expr [ ( OFFSET | , ) expr ] ]

select-core:
    SELECT [ DISTINCT | ALL ] result-column [, ...]
        [ FROM table-or-subquery [, ...] | join-clause ]
        [ WHERE expr ]
        [ GROUP BY expr [, ...] [ HAVING expr ] ]
        [ WINDOW window-name AS window-defn [, ...] ]
  | VALUES ( expr [, ...] ) [, ...]

Three things in that grammar are unlike PostgreSQL’s, and all three are visible in this type.

A compound operand is a bare select-core. There are no parentheses around it and none may be added — a parenthesised select is a table-or-subquery in SQLite, never a compound operand. So the ORDER BY and LIMIT after the last operand are the only ones there can be, they always apply to the whole compound, and this type therefore has one set of them rather than PostgreSQL’s two. See Compound.

OFFSET lives inside the LIMIT production. SELECT … OFFSET 5 with no LIMIT is a syntax error, so an offset without a limit is a recorded Error::Incomplete rather than SQL that will be rejected later.

VALUES (…), (…) is a select-core in its own right. values is that alternative: when it is non-empty the statement is a VALUES statement, and the clauses that only a SELECT core can carry are a recorded failure rather than silently dropped. A real SQLite additionally refuses ORDER BY/LIMIT when the last core is a VALUES, which its own parser accepts; that one is left to the engine, since whether it holds depends on what is compounded after the VALUES.

Fields§

§with: With

WITH ….

§distinct: bool

SELECT DISTINCT. false is ALL, the default, which adds nothing.

§select_list: SelectList

The result columns. Empty renders *.

§values: Values

The VALUES (…), (…) alternative to the whole SELECT core.

§from: TableRef

The first FROM item, with its joins.

§extra_from: Vec<TableRef>

Further comma-separated FROM items.

§where_: Where

WHERE ….

§group_by: GroupBy

GROUP BY ….

§having: Having

HAVING ….

§windows: Windows

WINDOW ….

§compounds: Compounds

The compound operands, applied left to right.

§order_by: OrderBy

ORDER BY …, which belongs to the whole compound when there is one.

§limit: Limit

LIMIT ….

§offset: Offset

OFFSET …, which cannot stand without a limit.

Implementations§

Source§

impl SelectQuery

Source

pub fn new() -> SelectQuery

An empty SELECT, which renders SELECT *.

Source

pub fn apply(&mut self, mods: impl Mod<SelectQuery>)

Apply more mods to an existing query.

Trait Implementations§

Source§

impl Clone for SelectQuery

Source§

fn clone(&self) -> SelectQuery

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 SelectQuery

Source§

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

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

impl Default for SelectQuery

Source§

fn default() -> SelectQuery

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

impl Expression for SelectQuery

Source§

fn write_sql(&self, w: &mut SqlWriter<'_>)

Append this fragment to w. Read more
Source§

impl HasCompounds for SelectQuery

Source§

fn compounds_mut(&mut self) -> &mut Compounds

The compound operands to modify.
Source§

impl HasExtraTables for SelectQuery

Source§

fn extra_tables_mut(&mut self) -> &mut Vec<TableRef>

The additional from-items to modify.
Source§

impl HasGroupBy for SelectQuery

Source§

fn group_by_mut(&mut self) -> &mut GroupBy

The GROUP BY clause to modify.
Source§

impl HasHaving for SelectQuery

Source§

fn having_mut(&mut self) -> &mut Having

The HAVING clause to modify.
Source§

impl HasJoins for SelectQuery

Source§

fn joins_mut(&mut self) -> &mut Vec<Join>

The join list to modify.
Source§

impl HasLimit for SelectQuery

Source§

fn limit_mut(&mut self) -> &mut Limit

The LIMIT clause to modify.
Source§

impl HasOffset for SelectQuery

Source§

fn offset_mut(&mut self) -> &mut Offset

The OFFSET clause to modify.
Source§

impl HasOrderBy for SelectQuery

Source§

fn order_by_mut(&mut self) -> &mut OrderBy

The ORDER BY clause to modify.
Source§

impl HasSelectList for SelectQuery

Source§

fn select_list_mut(&mut self) -> &mut SelectList

The projection to modify.
Source§

impl HasTableRef for SelectQuery

Source§

fn table_ref_mut(&mut self) -> &mut TableRef

The table reference to modify.
Source§

impl HasValues for SelectQuery

Source§

fn values_mut(&mut self) -> &mut Values

The row source to modify.
Source§

impl HasWhere for SelectQuery

Source§

fn where_mut(&mut self) -> &mut Where

The WHERE clause to modify.
Source§

impl HasWindows for SelectQuery

Source§

fn windows_mut(&mut self) -> &mut Windows

The WINDOW clause to modify.
Source§

impl HasWith for SelectQuery

Source§

fn with_mut(&mut self) -> &mut With

The WITH clause to modify.
Source§

impl IntoExpr for SelectQuery

Source§

fn into_expr(self) -> Expr

Perform the conversion.
Source§

impl IntoExprList for SelectQuery

Source§

fn into_expr_list(self) -> Vec<Expr>

Perform the conversion.
Source§

impl Query for SelectQuery

Source§

fn query_type(&self) -> QueryType

Which statement this renders.
Source§

fn dialect(&self) -> &dyn Dialect

The dialect this query renders itself in. Read more
Source§

fn build(&self) -> Result<(String, Vec<Value>), Error>

Render to SQL and arguments, numbering placeholders from 1. Read more
Source§

fn build_from(&self, start: usize) -> Result<(String, Vec<Value>), Error>

build with a different first placeholder position, for splicing into a statement that already has arguments — bob’s BuildN.
Source§

impl<H, L, M> QueryExtensions<H, L, M> for SelectQuery

Source§

fn hooks(&self) -> &[Hook]

Hooks to run before this query executes.
Source§

fn loaders(&self) -> &[Loader]

Loaders to run after this query executes, for eagerly loaded relations.
Source§

fn mapper_mods(&self) -> &[MapperMod]

Adjustments to the row mapper, for relations loaded in the same query.

Auto Trait Implementations§

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<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.