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 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", Alias::new("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",
Alias::new("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(Expr::expr(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ยงunsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
๐ฌThis is a nightly-only experimental API. (
clone_to_uninit
)