Skip to main content

SelectQuery

Struct SelectQuery 

Source
pub struct SelectQuery {
Show 16 fields pub with: With, pub hints: Hints, pub modifiers: Modifiers, pub select_list: SelectList, pub from: TableRef, pub extra_from: Vec<TableRef>, pub where_: Where, pub group_by: GroupBy, pub having: Having, pub windows: Windows, pub order_by: OrderBy, pub limit: Limit, pub offset: Offset, pub locks: Locks, pub lock_in_share_mode: bool, pub combines: Combines,
}
Expand description

A MySQL SELECT.

The field order is the clause order of https://dev.mysql.com/doc/refman/8.4/en/select.html:

[WITH [RECURSIVE] with_query [, ...]]
SELECT [hint_comment]
    [ALL | DISTINCT | DISTINCTROW] [HIGH_PRIORITY] [STRAIGHT_JOIN]
    [SQL_SMALL_RESULT] [SQL_BIG_RESULT] [SQL_BUFFER_RESULT]
    [SQL_NO_CACHE] [SQL_CALC_FOUND_ROWS]
    select_expr [, select_expr] ...
    [FROM table_references]
    [WHERE where_condition]
    [GROUP BY {col_name | expr | position}, ... [WITH ROLLUP]]
    [HAVING where_condition]
    [WINDOW window_name AS (window_spec) [, ...]]
    [ORDER BY {col_name | expr | position} [ASC | DESC], ...]
    [LIMIT {[offset,] row_count | row_count OFFSET offset}]
    [FOR {UPDATE | SHARE} [OF tbl_name [, ...]] [NOWAIT | SKIP LOCKED]
      | LOCK IN SHARE MODE]

Two differences from PostgreSQL are worth stating.

The locking clause has two shapes, and they are alternatives. FOR UPDATE and FOR SHARE are Locks; LOCK IN SHARE MODE is a production of its own with no OF list and no wait option, so it is a flag rather than a Lock strength. Setting both is a caller error the server refuses.

LIMIT gates OFFSET. MySQL’s grammar spells the pair as one clause, so OFFSET alone does not parse. Nothing here prevents it — the server is what says no.

Fields§

§with: With

WITH ….

§hints: Hints

/*+ … */.

§modifiers: Modifiers

DISTINCT, HIGH_PRIORITY, STRAIGHT_JOIN, …

§select_list: SelectList

The projection. Empty renders *.

§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 … [WITH ROLLUP].

§having: Having

HAVING ….

§windows: Windows

WINDOW ….

§order_by: OrderBy

ORDER BY … — this query’s own.

§limit: Limit

LIMIT … — this query’s own.

§offset: Offset

OFFSET … — this query’s own. Needs a LIMIT to be legal.

§locks: Locks

FOR UPDATE … / FOR SHARE ….

§lock_in_share_mode: bool

LOCK IN SHARE MODE, the pre-8.0 spelling of FOR SHARE.

§combines: Combines

The set operations, and the trailing clauses that belong to their result.

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 HasCombines for SelectQuery

Source§

fn combines_mut(&mut self) -> &mut Combines

The set operations to modify.
Source§

impl HasExtraTables for SelectQuery

Source§

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

The additional table references 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 HasHints for SelectQuery

Source§

fn hints_mut(&mut self) -> &mut Hints

The hints to add to.
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 HasLocks for SelectQuery

Source§

fn locks_mut(&mut self) -> &mut Locks

The locking clauses to modify.
Source§

impl HasModifiers for SelectQuery

Source§

fn modifiers_mut(&mut self) -> &mut Modifiers

The modifiers to add to.
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 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.