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_nameMySQL 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
impl Function
Sourcepub fn new(
name: impl Into<Cow<'static, str>>,
args: impl IntoExprList,
) -> Function
pub fn new( name: impl Into<Cow<'static, str>>, args: impl IntoExprList, ) -> Function
A call to name with args.
Sourcepub fn distinct(self) -> Function
pub fn distinct(self) -> Function
DISTINCT, for an aggregate that should see each distinct input once.
Sourcepub fn order_by(self, order: impl IntoExpr) -> Function
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).
Sourcepub fn separator(self, separator: impl Into<Cow<'static, str>>) -> Function
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.
Sourcepub fn over(self, mods: impl Mod<Window>) -> Expr
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.
Trait Implementations§
Source§impl Expression for Function
impl Expression for Function
Source§impl HasOrderBy for Function
impl HasOrderBy for Function
Source§fn order_by_mut(&mut self) -> &mut OrderBy
fn order_by_mut(&mut self) -> &mut OrderBy
ORDER BY clause to modify.