Skip to main content

Function

Struct Function 

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

A SQLite function call, with the decorations SQLite’s grammar hangs off one.

From https://www.sqlite.org/syntax/aggregate-function-invocation.html and https://www.sqlite.org/syntax/window-function-invocation.html:

name ( [ DISTINCT ] expr [, ...] [ ORDER BY ordering-term [, ...] ] | * )
    [ FILTER ( WHERE expr ) ]
name ( expr [, ...] | * ) [ FILTER ( WHERE expr ) ]
    OVER ( window-defn | window-name )

That is the whole list, and it is shorter than PostgreSQL’s. SQLite has no WITHIN GROUP (ORDER BY …) — an ordered-set aggregate is not a thing it has — and no column-definition list on a table-valued function, so neither appears here. The aggregate ORDER BY inside the argument list needs SQLite 3.44 or later.

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

// count(*) OVER (PARTITION BY "user_id")
let e = f("count", "*").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, inside the argument list: group_concat("name" ORDER BY "id").

SQLite 3.44 and later.

Source

pub fn filter(self, condition: impl IntoExpr) -> Function

Add a condition to FILTER (WHERE …). Several are AND-joined.

Source

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

Attach OVER (…), built from window and frame mods.

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

To reference a window declared in the statement’s WINDOW clause use over_name, not over(window::based_on(..)) — the parenthesised form is the copying one.

Source

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

Attach OVER "w" — a reference to a window in the statement’s WINDOW 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 result-column 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.