Skip to main content

Function

Struct Function 

Source
pub struct Function { /* private fields */ }
Expand description

A MySQL function call, with every decoration the grammar hangs off one.

From 14.19 Aggregate Functions and 14.20 Window Functions:

name([DISTINCT] expr [, expr] ... [ORDER BY …])
GROUP_CONCAT([DISTINCT] expr [, expr] ... [ORDER BY …] [SEPARATOR str_val])
name(…) OVER (window_spec) | name(…) OVER window_name

MySQL has no FILTER (WHERE …) and no WITHIN GROUP. Both are on PostgreSQL’s function builder and neither is here.

Expr::Func carries only what all three dialects share, so everything above lives here and reaches core through Expr::Custom.

use keelson_mysql::{f, quote, window};

// AVG(`views`) OVER (PARTITION BY `user_id`)
let e = f("AVG", quote("views")).over(window::partition_by(quote("user_id")));

Implementations§

Source§

impl Function

Source

pub fn new( name: impl Into<Cow<'static, str>>, args: impl IntoExprList, ) -> Function

A call to name with args.

Source

pub fn distinct(self) -> Function

DISTINCT, for an aggregate that should see each distinct input once.

Source

pub fn order_by(self, order: impl IntoExpr) -> Function

Add a sort key to the aggregate’s own ORDER BY, rendered inside the argument list: GROUP_CONCAT(x ORDER BY y).

Source

pub fn separator(self, separator: impl Into<Cow<'static, str>>) -> Function

SEPARATOR 'str', which only GROUP_CONCAT takes.

Written as a single-quoted literal with nothing escaped, exactly like s: this is for a separator the program itself chose.

Source

pub fn over(self, mods: impl Mod<Window>) -> Expr

Attach OVER (…), built from window mods — mysql::window::* and mysql::frame::*.

Ends the builder, because OVER is the last thing in the grammar and nothing may follow it. over(()) gives the legal OVER (), which means the whole partition.

Source

pub fn over_name(self, name: impl Into<Cow<'static, str>>) -> Expr

Attach OVER \w`— a reference to a window in the statement'sWINDOW` clause.

Unparenthesised, which is what makes it a reference rather than a copy.

Source

pub fn as_(self, alias: impl Into<Cow<'static, str>>) -> Expr

f(…) AS \alias`` — the select-list alias.

Ends the builder for the same reason Chain::as_ does: an alias is not an operand.

Trait Implementations§

Source§

impl Clone for Function

Source§

fn clone(&self) -> Function

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 Function

Source§

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

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

impl Default for Function

Source§

fn default() -> Function

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

impl Expression for Function

Source§

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

Append this fragment to w. Read more
Source§

impl HasOrderBy for Function

Source§

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

The ORDER BY clause to modify.
Source§

impl IntoExpr for Function

Source§

fn into_expr(self) -> Expr

Perform the conversion.
Source§

impl IntoExprList for Function

Source§

fn into_expr_list(self) -> Vec<Expr>

Perform the conversion.

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.