Struct sea_query::func::Func [−][src]
pub struct Func;
Expand description
Function call helper.
Implementations
Call a custom function.
Examples
use sea_query::{*, tests_cfg::*};
struct MyFunction;
impl Iden for MyFunction {
fn unquoted(&self, s: &mut dyn FmtWrite) {
write!(s, "MY_FUNCTION").unwrap();
}
}
let query = Query::select()
.expr(Func::cust(MyFunction).args(vec![Expr::val("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')"#
);
Call MAX
function.
Examples
use sea_query::{*, tests_cfg::*};
let query = Query::select()
.expr(Func::max(Expr::tbl(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`"#
);
Call MIN
function.
Examples
use sea_query::{*, tests_cfg::*};
let query = Query::select()
.expr(Func::min(Expr::tbl(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`"#
);
Call SUM
function.
Examples
use sea_query::{*, tests_cfg::*};
let query = Query::select()
.expr(Func::sum(Expr::tbl(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`"#
);
Call AVG
function.
Examples
use sea_query::{*, tests_cfg::*};
let query = Query::select()
.expr(Func::avg(Expr::tbl(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`"#
);
Call COUNT
function.
Examples
use sea_query::{*, tests_cfg::*};
let query = Query::select()
.expr(Func::count(Expr::tbl(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`"#
);
Call CHAR_LENGTH
function.
Examples
use sea_query::{*, tests_cfg::*};
let query = Query::select()
.expr(Func::char_length(Expr::tbl(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`"#
);
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`"#
);
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Func
impl UnwindSafe for Func
Blanket Implementations
Mutably borrows from an owned value. Read more
type Output = T
type Output = T
Should always be Self