pub struct Func;Expand description
Function call helper.
Implementations§
Source§impl Func
 
impl Func
Sourcepub fn cust<T>(func: T) -> FunctionCallwhere
    T: IntoIden,
 
pub fn cust<T>(func: T) -> FunctionCallwhere
    T: IntoIden,
Call a custom function.
§Examples
use sea_query::{tests_cfg::*, *};
struct MyFunction;
impl Iden for MyFunction {
    fn unquoted(&self, s: &mut dyn Write) {
        write!(s, "MY_FUNCTION").unwrap();
    }
}
let query = Query::select()
    .expr(Func::cust(MyFunction).arg("hello"))
    .to_owned();
assert_eq!(
    query.to_string(MysqlQueryBuilder),
    r#"SELECT MY_FUNCTION('hello')"#
);
assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT MY_FUNCTION('hello')"#
);
assert_eq!(
    query.to_string(SqliteQueryBuilder),
    r#"SELECT MY_FUNCTION('hello')"#
);Sourcepub fn max<T>(expr: T) -> FunctionCallwhere
    T: Into<SimpleExpr>,
 
pub fn max<T>(expr: T) -> FunctionCallwhere
    T: Into<SimpleExpr>,
Call MAX function.
§Examples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
    .expr(Func::max(Expr::col((Char::Table, Char::SizeW))))
    .from(Char::Table)
    .to_owned();
assert_eq!(
    query.to_string(MysqlQueryBuilder),
    r#"SELECT MAX(`character`.`size_w`) FROM `character`"#
);
assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT MAX("character"."size_w") FROM "character""#
);
assert_eq!(
    query.to_string(SqliteQueryBuilder),
    r#"SELECT MAX("character"."size_w") FROM "character""#
);Sourcepub fn min<T>(expr: T) -> FunctionCallwhere
    T: Into<SimpleExpr>,
 
pub fn min<T>(expr: T) -> FunctionCallwhere
    T: Into<SimpleExpr>,
Call MIN function.
§Examples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
    .expr(Func::min(Expr::col((Char::Table, Char::SizeH))))
    .from(Char::Table)
    .to_owned();
assert_eq!(
    query.to_string(MysqlQueryBuilder),
    r#"SELECT MIN(`character`.`size_h`) FROM `character`"#
);
assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT MIN("character"."size_h") FROM "character""#
);
assert_eq!(
    query.to_string(SqliteQueryBuilder),
    r#"SELECT MIN("character"."size_h") FROM "character""#
);Sourcepub fn sum<T>(expr: T) -> FunctionCallwhere
    T: Into<SimpleExpr>,
 
pub fn sum<T>(expr: T) -> FunctionCallwhere
    T: Into<SimpleExpr>,
Call SUM function.
§Examples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
    .expr(Func::sum(Expr::col((Char::Table, Char::SizeH))))
    .from(Char::Table)
    .to_owned();
assert_eq!(
    query.to_string(MysqlQueryBuilder),
    r#"SELECT SUM(`character`.`size_h`) FROM `character`"#
);
assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT SUM("character"."size_h") FROM "character""#
);
assert_eq!(
    query.to_string(SqliteQueryBuilder),
    r#"SELECT SUM("character"."size_h") FROM "character""#
);Sourcepub fn avg<T>(expr: T) -> FunctionCallwhere
    T: Into<SimpleExpr>,
 
pub fn avg<T>(expr: T) -> FunctionCallwhere
    T: Into<SimpleExpr>,
Call AVG function.
§Examples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
    .expr(Func::avg(Expr::col((Char::Table, Char::SizeH))))
    .from(Char::Table)
    .to_owned();
assert_eq!(
    query.to_string(MysqlQueryBuilder),
    r#"SELECT AVG(`character`.`size_h`) FROM `character`"#
);
assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT AVG("character"."size_h") FROM "character""#
);
assert_eq!(
    query.to_string(SqliteQueryBuilder),
    r#"SELECT AVG("character"."size_h") FROM "character""#
);Sourcepub fn abs<T>(expr: T) -> FunctionCallwhere
    T: Into<SimpleExpr>,
 
pub fn abs<T>(expr: T) -> FunctionCallwhere
    T: Into<SimpleExpr>,
Call ABS function.
§Examples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
    .expr(Func::abs(Expr::col((Char::Table, Char::SizeH))))
    .from(Char::Table)
    .to_owned();
assert_eq!(
    query.to_string(MysqlQueryBuilder),
    r#"SELECT ABS(`character`.`size_h`) FROM `character`"#
);
assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT ABS("character"."size_h") FROM "character""#
);
assert_eq!(
    query.to_string(SqliteQueryBuilder),
    r#"SELECT ABS("character"."size_h") FROM "character""#
);Sourcepub fn count<T>(expr: T) -> FunctionCallwhere
    T: Into<SimpleExpr>,
 
pub fn count<T>(expr: T) -> FunctionCallwhere
    T: Into<SimpleExpr>,
Call COUNT function.
§Examples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
    .expr(Func::count(Expr::col((Char::Table, Char::Id))))
    .from(Char::Table)
    .to_owned();
assert_eq!(
    query.to_string(MysqlQueryBuilder),
    r#"SELECT COUNT(`character`.`id`) FROM `character`"#
);
assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT COUNT("character"."id") FROM "character""#
);
assert_eq!(
    query.to_string(SqliteQueryBuilder),
    r#"SELECT COUNT("character"."id") FROM "character""#
);Sourcepub fn count_distinct<T>(expr: T) -> FunctionCallwhere
    T: Into<SimpleExpr>,
 
pub fn count_distinct<T>(expr: T) -> FunctionCallwhere
    T: Into<SimpleExpr>,
Call COUNT function with the DISTINCT modifier.
§Examples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
    .expr(Func::count_distinct(Expr::col((Char::Table, Char::Id))))
    .from(Char::Table)
    .to_owned();
assert_eq!(
    query.to_string(MysqlQueryBuilder),
    r#"SELECT COUNT(DISTINCT `character`.`id`) FROM `character`"#
);
assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT COUNT(DISTINCT "character"."id") FROM "character""#
);
assert_eq!(
    query.to_string(SqliteQueryBuilder),
    r#"SELECT COUNT(DISTINCT "character"."id") FROM "character""#
);Sourcepub fn char_length<T>(expr: T) -> FunctionCallwhere
    T: Into<SimpleExpr>,
 
pub fn char_length<T>(expr: T) -> FunctionCallwhere
    T: Into<SimpleExpr>,
Call CHAR_LENGTH function.
§Examples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
    .expr(Func::char_length(Expr::col((Char::Table, Char::Character))))
    .from(Char::Table)
    .to_owned();
assert_eq!(
    query.to_string(MysqlQueryBuilder),
    r#"SELECT CHAR_LENGTH(`character`.`character`) FROM `character`"#
);
assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT CHAR_LENGTH("character"."character") FROM "character""#
);
assert_eq!(
    query.to_string(SqliteQueryBuilder),
    r#"SELECT LENGTH("character"."character") FROM "character""#
);Sourcepub fn greatest<I>(args: I) -> FunctionCallwhere
    I: IntoIterator<Item = SimpleExpr>,
 
pub fn greatest<I>(args: I) -> FunctionCallwhere
    I: IntoIterator<Item = SimpleExpr>,
Call GREATEST function.
§Examples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
    .expr(Func::greatest([
        Expr::col(Char::SizeW).into(),
        Expr::col(Char::SizeH).into(),
    ]))
    .from(Char::Table)
    .to_owned();
assert_eq!(
    query.to_string(MysqlQueryBuilder),
    r#"SELECT GREATEST(`size_w`, `size_h`) FROM `character`"#
);
assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT GREATEST("size_w", "size_h") FROM "character""#
);
assert_eq!(
    query.to_string(SqliteQueryBuilder),
    r#"SELECT MAX("size_w", "size_h") FROM "character""#
);Sourcepub fn least<I>(args: I) -> FunctionCallwhere
    I: IntoIterator<Item = SimpleExpr>,
 
pub fn least<I>(args: I) -> FunctionCallwhere
    I: IntoIterator<Item = SimpleExpr>,
Call LEAST function.
§Examples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
    .expr(Func::least([
        Expr::col(Char::SizeW).into(),
        Expr::col(Char::SizeH).into(),
    ]))
    .from(Char::Table)
    .to_owned();
assert_eq!(
    query.to_string(MysqlQueryBuilder),
    r#"SELECT LEAST(`size_w`, `size_h`) FROM `character`"#
);
assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT LEAST("size_w", "size_h") FROM "character""#
);
assert_eq!(
    query.to_string(SqliteQueryBuilder),
    r#"SELECT MIN("size_w", "size_h") FROM "character""#
);Sourcepub fn if_null<A, B>(a: A, b: B) -> FunctionCall
 
pub fn if_null<A, B>(a: A, b: B) -> FunctionCall
Call IF NULL function.
§Examples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
    .expr(Func::if_null(
        Expr::col(Char::SizeW),
        Expr::col(Char::SizeH),
    ))
    .from(Char::Table)
    .to_owned();
assert_eq!(
    query.to_string(MysqlQueryBuilder),
    r#"SELECT IFNULL(`size_w`, `size_h`) FROM `character`"#
);
assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT COALESCE("size_w", "size_h") FROM "character""#
);
assert_eq!(
    query.to_string(SqliteQueryBuilder),
    r#"SELECT IFNULL("size_w", "size_h") FROM "character""#
);Sourcepub fn cast_as<V, I>(expr: V, iden: I) -> FunctionCall
 
pub fn cast_as<V, I>(expr: V, iden: I) -> FunctionCall
Call CAST function with a custom type.
§Examples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
    .expr(Func::cast_as("hello", "MyType"))
    .to_owned();
assert_eq!(
    query.to_string(MysqlQueryBuilder),
    r#"SELECT CAST('hello' AS MyType)"#
);
assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT CAST('hello' AS MyType)"#
);
assert_eq!(
    query.to_string(SqliteQueryBuilder),
    r#"SELECT CAST('hello' AS MyType)"#
);Sourcepub fn cast_as_quoted<V, I>(expr: V, iden: I, q: Quote) -> FunctionCall
 
pub fn cast_as_quoted<V, I>(expr: V, iden: I, q: Quote) -> FunctionCall
Call CAST function with a case-sensitive custom type.
§Examples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
    .expr(Func::cast_as_quoted("hello", "MyType", '"'.into()))
    .to_owned();
assert_eq!(
    query.to_string(MysqlQueryBuilder),
    r#"SELECT CAST('hello' AS "MyType")"#
);
assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT CAST('hello' AS "MyType")"#
);
assert_eq!(
    query.to_string(SqliteQueryBuilder),
    r#"SELECT CAST('hello' AS "MyType")"#
);Sourcepub fn coalesce<I>(args: I) -> FunctionCallwhere
    I: IntoIterator<Item = SimpleExpr>,
 
pub fn coalesce<I>(args: I) -> FunctionCallwhere
    I: IntoIterator<Item = SimpleExpr>,
Call COALESCE function.
§Examples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
    .expr(Func::coalesce([
        Expr::col(Char::SizeW).into(),
        Expr::col(Char::SizeH).into(),
        Expr::val(12).into(),
    ]))
    .from(Char::Table)
    .to_owned();
assert_eq!(
    query.to_string(MysqlQueryBuilder),
    r#"SELECT COALESCE(`size_w`, `size_h`, 12) FROM `character`"#
);
assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT COALESCE("size_w", "size_h", 12) FROM "character""#
);
assert_eq!(
    query.to_string(SqliteQueryBuilder),
    r#"SELECT COALESCE("size_w", "size_h", 12) FROM "character""#
);Sourcepub fn lower<T>(expr: T) -> FunctionCallwhere
    T: Into<SimpleExpr>,
 
pub fn lower<T>(expr: T) -> FunctionCallwhere
    T: Into<SimpleExpr>,
Call LOWER function.
§Examples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
    .expr(Func::lower(Expr::col(Char::Character)))
    .from(Char::Table)
    .to_owned();
assert_eq!(
    query.to_string(MysqlQueryBuilder),
    r#"SELECT LOWER(`character`) FROM `character`"#
);
assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT LOWER("character") FROM "character""#
);
assert_eq!(
    query.to_string(SqliteQueryBuilder),
    r#"SELECT LOWER("character") FROM "character""#
);use sea_query::{tests_cfg::*, *};
let query = Query::select()
    .column(Font::Id)
    .from(Font::Table)
    .and_where(Func::lower(Expr::col(Font::Name)).eq("abc".trim().to_lowercase()))
    .take();
assert_eq!(
    query.to_string(MysqlQueryBuilder),
    "SELECT `id` FROM `font` WHERE LOWER(`name`) = 'abc'"
);
assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT "id" FROM "font" WHERE LOWER("name") = 'abc'"#
);
assert_eq!(
    query.to_string(SqliteQueryBuilder),
    r#"SELECT "id" FROM "font" WHERE LOWER("name") = 'abc'"#
);Sourcepub fn upper<T>(expr: T) -> FunctionCallwhere
    T: Into<SimpleExpr>,
 
pub fn upper<T>(expr: T) -> FunctionCallwhere
    T: Into<SimpleExpr>,
Call UPPER function.
§Examples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
    .expr(Func::upper(Expr::col(Char::Character)))
    .from(Char::Table)
    .to_owned();
assert_eq!(
    query.to_string(MysqlQueryBuilder),
    r#"SELECT UPPER(`character`) FROM `character`"#
);
assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT UPPER("character") FROM "character""#
);
assert_eq!(
    query.to_string(SqliteQueryBuilder),
    r#"SELECT UPPER("character") FROM "character""#
);Sourcepub fn bit_and<T>(expr: T) -> FunctionCallwhere
    T: Into<SimpleExpr>,
 
pub fn bit_and<T>(expr: T) -> FunctionCallwhere
    T: Into<SimpleExpr>,
Call BIT_AND function, this is not supported on SQLite.
§Examples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
    .expr(Func::bit_and(Expr::col(Char::FontSize)))
    .from(Char::Table)
    .to_owned();
assert_eq!(
    query.to_string(MysqlQueryBuilder),
    r#"SELECT BIT_AND(`font_size`) FROM `character`"#
);
assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT BIT_AND("font_size") FROM "character""#
);Sourcepub fn bit_or<T>(expr: T) -> FunctionCallwhere
    T: Into<SimpleExpr>,
 
pub fn bit_or<T>(expr: T) -> FunctionCallwhere
    T: Into<SimpleExpr>,
Call BIT_OR function, this is not supported on SQLite.
§Examples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
    .expr(Func::bit_or(Expr::col(Char::FontSize)))
    .from(Char::Table)
    .to_owned();
assert_eq!(
    query.to_string(MysqlQueryBuilder),
    r#"SELECT BIT_OR(`font_size`) FROM `character`"#
);
assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT BIT_OR("font_size") FROM "character""#
);Sourcepub fn round<A>(expr: A) -> FunctionCallwhere
    A: Into<SimpleExpr>,
 
pub fn round<A>(expr: A) -> FunctionCallwhere
    A: Into<SimpleExpr>,
Call ROUND function.
§Examples
use sea_query::tests_cfg::Character::Character;
use sea_query::{tests_cfg::*, *};
let query = Query::select().expr(Func::round(5.654)).to_owned();
assert_eq!(query.to_string(MysqlQueryBuilder), r#"SELECT ROUND(5.654)"#);
assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT ROUND(5.654)"#
);
assert_eq!(
    query.to_string(SqliteQueryBuilder),
    r#"SELECT ROUND(5.654)"#
);Sourcepub fn round_with_precision<A, B>(a: A, b: B) -> FunctionCall
 
pub fn round_with_precision<A, B>(a: A, b: B) -> FunctionCall
Call ROUND function with the precision.
§Examples
use sea_query::tests_cfg::Character::Character;
use sea_query::{tests_cfg::*, *};
let query = Query::select()
    .expr(Func::round_with_precision(5.654, 2))
    .to_owned();
assert_eq!(
    query.to_string(MysqlQueryBuilder),
    r#"SELECT ROUND(5.654, 2)"#
);
assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT ROUND(5.654, 2)"#
);
assert_eq!(
    query.to_string(SqliteQueryBuilder),
    r#"SELECT ROUND(5.654, 2)"#
);Sourcepub fn random() -> FunctionCall
 
pub fn random() -> FunctionCall
Call RANDOM function.
§Examples
use sea_query::tests_cfg::Character::Character;
use sea_query::{tests_cfg::*, *};
let query = Query::select().expr(Func::random()).to_owned();
assert_eq!(query.to_string(MysqlQueryBuilder), r#"SELECT RAND()"#);
assert_eq!(query.to_string(PostgresQueryBuilder), r#"SELECT RANDOM()"#);
assert_eq!(query.to_string(SqliteQueryBuilder), r#"SELECT RANDOM()"#);Sourcepub fn md5<T>(expr: T) -> FunctionCallwhere
    T: Into<SimpleExpr>,
 
pub fn md5<T>(expr: T) -> FunctionCallwhere
    T: Into<SimpleExpr>,
Call MD5 function, this is only available in Postgres and MySQL.
§Examples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
    .expr(Func::md5(Expr::col((Char::Table, Char::Character))))
    .from(Char::Table)
    .to_owned();
assert_eq!(
    query.to_string(MysqlQueryBuilder),
    r#"SELECT MD5(`character`.`character`) FROM `character`"#
);
assert_eq!(
    query.to_string(PostgresQueryBuilder),
    r#"SELECT MD5("character"."character") FROM "character""#
);Trait Implementations§
Auto Trait Implementations§
impl Freeze for Func
impl RefUnwindSafe for Func
impl Send for Func
impl Sync for Func
impl Unpin for Func
impl UnwindSafe for Func
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
    T: ?Sized,
 
impl<T> BorrowMut<T> for Twhere
    T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
 
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
    T: Clone,
 
impl<T> CloneToUninit for Twhere
    T: Clone,
Source§impl<T> Instrument for T
 
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
 
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
 
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
 
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
 
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts 
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
 
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts 
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more