pub struct Expr { /* private fields */ }
Expand description
Helper to build a SimpleExpr
.
Implementationsยง
sourceยงimpl Expr
impl Expr
pub fn asterisk() -> Self
Asterisk
]sourcepub fn col<T>(n: T) -> Selfwhere
T: IntoColumnRef,
pub fn col<T>(n: T) -> Selfwhere
T: IntoColumnRef,
Express the target column without table prefix.
ยงExamples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where(Expr::col(Char::SizeW).eq(1))
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"SELECT `character`, `size_w`, `size_h` FROM `character` WHERE `size_w` = 1"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "size_w" = 1"#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "size_w" = 1"#
);
use sea_query::{tests_cfg::*, *};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where(Expr::col((Char::Table, Char::SizeW)).eq(1))
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"SELECT `character`, `size_w`, `size_h` FROM `character` WHERE `character`.`size_w` = 1"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "character"."size_w" = 1"#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "character"."size_w" = 1"#
);
sourcepub fn tuple<I>(n: I) -> Selfwhere
I: IntoIterator<Item = SimpleExpr>,
pub fn tuple<I>(n: I) -> Selfwhere
I: IntoIterator<Item = SimpleExpr>,
Wraps tuple of SimpleExpr
, can be used for tuple comparison
ยงExamples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where(
Expr::tuple([Expr::col(Char::SizeW).into(), Expr::value(100)])
.lt(Expr::tuple([Expr::value(500), Expr::value(100)])))
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"SELECT `character`, `size_w`, `size_h` FROM `character` WHERE (`size_w`, 100) < (500, 100)"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE ("size_w", 100) < (500, 100)"#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE ("size_w", 100) < (500, 100)"#
);
pub fn table_asterisk<T>(t: T) -> Selfwhere
T: IntoIden,
Asterisk
]sourcepub fn val<V>(v: V) -> Self
pub fn val<V>(v: V) -> Self
Express a Value
, returning a Expr
.
ยงExamples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where(Expr::val(1).into())
.and_where(Expr::val(2.5).into())
.and_where(Expr::val("3").into())
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"SELECT `character`, `size_w`, `size_h` FROM `character` WHERE 1 AND 2.5 AND '3'"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE 1 AND 2.5 AND '3'"#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE 1 AND 2.5 AND '3'"#
);
sourcepub fn expr<T>(expr: T) -> Selfwhere
T: Into<SimpleExpr>,
pub fn expr<T>(expr: T) -> Selfwhere
T: Into<SimpleExpr>,
Wrap a SimpleExpr
and perform some operation on it.
ยงExamples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where(Expr::expr(Expr::col(Char::SizeW).if_null(0)).gt(2))
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"SELECT `character`, `size_w`, `size_h` FROM `character` WHERE IFNULL(`size_w`, 0) > 2"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE COALESCE("size_w", 0) > 2"#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE IFNULL("size_w", 0) > 2"#
);
use sea_query::{tests_cfg::*, *};
let query = Query::select()
.column(Char::Character)
.from(Char::Table)
.and_where(Expr::expr(Func::lower(Expr::col(Char::Character))).is_in(["a", "b"]))
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"SELECT `character` FROM `character` WHERE LOWER(`character`) IN ('a', 'b')"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT "character" FROM "character" WHERE LOWER("character") IN ('a', 'b')"#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"SELECT "character" FROM "character" WHERE LOWER("character") IN ('a', 'b')"#
);
sourcepub fn value<V>(v: V) -> SimpleExprwhere
V: Into<SimpleExpr>,
pub fn value<V>(v: V) -> SimpleExprwhere
V: Into<SimpleExpr>,
Express a Value
, returning a SimpleExpr
.
ยงExamples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where(Expr::value(1))
.and_where(Expr::value(2.5))
.and_where(Expr::value("3"))
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"SELECT `character`, `size_w`, `size_h` FROM `character` WHERE 1 AND 2.5 AND '3'"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE 1 AND 2.5 AND '3'"#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE 1 AND 2.5 AND '3'"#
);
sourcepub fn cust<T>(s: T) -> SimpleExpr
pub fn cust<T>(s: T) -> SimpleExpr
Express any custom expression in &str
.
ยงExamples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where(Expr::cust("1 = 1"))
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"SELECT `character`, `size_w`, `size_h` FROM `character` WHERE 1 = 1"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE 1 = 1"#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE 1 = 1"#
);
sourcepub fn cust_with_values<T, V, I>(s: T, v: I) -> SimpleExpr
pub fn cust_with_values<T, V, I>(s: T, v: I) -> SimpleExpr
Express any custom expression with Value
. Use this if your expression needs variables.
ยงExamples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where(Expr::col(Char::Id).eq(1))
.and_where(Expr::cust_with_values("6 = ? * ?", [2, 3]))
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"SELECT `character`, `size_w`, `size_h` FROM `character` WHERE `id` = 1 AND (6 = 2 * 3)"#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "id" = 1 AND (6 = 2 * 3)"#
);
use sea_query::{tests_cfg::*, *};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where(Expr::col(Char::Id).eq(1))
.and_where(Expr::cust_with_values("6 = $2 * $1", [3, 2]))
.to_owned();
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "id" = 1 AND (6 = 2 * 3)"#
);
use sea_query::{tests_cfg::*, *};
let query = Query::select()
.expr(Expr::cust_with_values("6 = ? * ?", [2, 3]))
.to_owned();
assert_eq!(query.to_string(MysqlQueryBuilder), r#"SELECT 6 = 2 * 3"#);
assert_eq!(query.to_string(SqliteQueryBuilder), r#"SELECT 6 = 2 * 3"#);
Postgres only: use $$
to escape $
use sea_query::{tests_cfg::*, *};
let query = Query::select()
.expr(Expr::cust_with_values("$1 $$ $2", ["a", "b"]))
.to_owned();
assert_eq!(query.to_string(PostgresQueryBuilder), r#"SELECT 'a' $ 'b'"#);
use sea_query::{tests_cfg::*, *};
let query = Query::select()
.expr(Expr::cust_with_values("data @? ($1::JSONPATH)", ["hello"]))
.to_owned();
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT data @? ('hello'::JSONPATH)"#
);
sourcepub fn cust_with_expr<T, E>(s: T, expr: E) -> SimpleExpr
pub fn cust_with_expr<T, E>(s: T, expr: E) -> SimpleExpr
Express any custom expression with SimpleExpr
. Use this if your expression needs other expression.
ยงExamples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
.expr(Expr::val(1).add(2))
.expr(Expr::cust_with_expr("data @? ($1::JSONPATH)", "hello"))
.to_owned();
let (sql, values) = query.build(PostgresQueryBuilder);
assert_eq!(sql, r#"SELECT $1 + $2, data @? ($3::JSONPATH)"#);
assert_eq!(
values,
Values(vec![1i32.into(), 2i32.into(), "hello".into()])
);
use sea_query::{tests_cfg::*, *};
let query = Query::select()
.expr(Expr::cust_with_expr(
"json_agg(DISTINCT $1)",
Expr::col(Char::Character),
))
.to_owned();
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT json_agg(DISTINCT "character")"#
);
sourcepub fn cust_with_exprs<T, I>(s: T, v: I) -> SimpleExpr
pub fn cust_with_exprs<T, I>(s: T, v: I) -> SimpleExpr
Express any custom expression with SimpleExpr
. Use this if your expression needs other expressions.
sourcepub fn eq<V>(self, v: V) -> SimpleExprwhere
V: Into<SimpleExpr>,
pub fn eq<V>(self, v: V) -> SimpleExprwhere
V: Into<SimpleExpr>,
Express an equal (=
) expression.
This is equivalent to a newer ExprTrait::eq and may require more some wrapping beforehand.
ยงExamples
use sea_query::{*, tests_cfg::*};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where(Expr::val("What!").eq("Nothing"))
.and_where(Expr::col(Char::Id).eq(1))
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"SELECT `character`, `size_w`, `size_h` FROM `character` WHERE 'What!' = 'Nothing' AND `id` = 1"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE 'What!' = 'Nothing' AND "id" = 1"#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE 'What!' = 'Nothing' AND "id" = 1"#
);
sourcepub fn ne<V>(self, v: V) -> SimpleExprwhere
V: Into<SimpleExpr>,
pub fn ne<V>(self, v: V) -> SimpleExprwhere
V: Into<SimpleExpr>,
Express a not equal (<>
) expression.
This is equivalent to a newer ExprTrait::ne and may require more some wrapping beforehand.
ยงExamples
use sea_query::{*, tests_cfg::*};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where(Expr::val("Morning").ne("Good"))
.and_where(Expr::col(Char::Id).ne(1))
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"SELECT `character`, `size_w`, `size_h` FROM `character` WHERE 'Morning' <> 'Good' AND `id` <> 1"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE 'Morning' <> 'Good' AND "id" <> 1"#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE 'Morning' <> 'Good' AND "id" <> 1"#
);
sourcepub fn equals<C>(self, col: C) -> SimpleExprwhere
C: IntoColumnRef,
pub fn equals<C>(self, col: C) -> SimpleExprwhere
C: IntoColumnRef,
Express a equal expression between two table columns, you will mainly use this to relate identical value between two table columns.
This is equivalent to a newer ExprTrait::equals and may require more some wrapping beforehand.
ยงExamples
use sea_query::{*, tests_cfg::*};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where(Expr::col((Char::Table, Char::FontId)).equals((Font::Table, Font::Id)))
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"SELECT `character`, `size_w`, `size_h` FROM `character` WHERE `character`.`font_id` = `font`.`id`"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "character"."font_id" = "font"."id""#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "character"."font_id" = "font"."id""#
);
sourcepub fn not_equals<C>(self, col: C) -> SimpleExprwhere
C: IntoColumnRef,
pub fn not_equals<C>(self, col: C) -> SimpleExprwhere
C: IntoColumnRef,
Express a not equal expression between two table columns, you will mainly use this to relate identical value between two table columns.
This is equivalent to a newer ExprTrait::not_equals and may require more some wrapping beforehand.
ยงExamples
use sea_query::{*, tests_cfg::*};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where(Expr::col((Char::Table, Char::FontId)).not_equals((Font::Table, Font::Id)))
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"SELECT `character`, `size_w`, `size_h` FROM `character` WHERE `character`.`font_id` <> `font`.`id`"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "character"."font_id" <> "font"."id""#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "character"."font_id" <> "font"."id""#
);
sourcepub fn gt<V>(self, v: V) -> SimpleExprwhere
V: Into<SimpleExpr>,
pub fn gt<V>(self, v: V) -> SimpleExprwhere
V: Into<SimpleExpr>,
Express a greater than (>
) expression.
This is equivalent to a newer ExprTrait::gt and may require more some wrapping beforehand.
ยงExamples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where(Expr::col((Char::Table, Char::SizeW)).gt(2))
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"SELECT `character`, `size_w`, `size_h` FROM `character` WHERE `character`.`size_w` > 2"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "character"."size_w" > 2"#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "character"."size_w" > 2"#
);
sourcepub fn gte<V>(self, v: V) -> SimpleExprwhere
V: Into<SimpleExpr>,
pub fn gte<V>(self, v: V) -> SimpleExprwhere
V: Into<SimpleExpr>,
Express a greater than or equal (>=
) expression.
This is equivalent to a newer ExprTrait::gte and may require more some wrapping beforehand.
ยงExamples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where(Expr::col((Char::Table, Char::SizeW)).gte(2))
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"SELECT `character`, `size_w`, `size_h` FROM `character` WHERE `character`.`size_w` >= 2"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "character"."size_w" >= 2"#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "character"."size_w" >= 2"#
);
sourcepub fn lt<V>(self, v: V) -> SimpleExprwhere
V: Into<SimpleExpr>,
pub fn lt<V>(self, v: V) -> SimpleExprwhere
V: Into<SimpleExpr>,
Express a less than (<
) expression.
This is equivalent to a newer ExprTrait::lt and may require more some wrapping beforehand.
ยงExamples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where(Expr::col((Char::Table, Char::SizeW)).lt(2))
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"SELECT `character`, `size_w`, `size_h` FROM `character` WHERE `character`.`size_w` < 2"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "character"."size_w" < 2"#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "character"."size_w" < 2"#
);
sourcepub fn lte<V>(self, v: V) -> SimpleExprwhere
V: Into<SimpleExpr>,
pub fn lte<V>(self, v: V) -> SimpleExprwhere
V: Into<SimpleExpr>,
Express a less than or equal (<=
) expression.
This is equivalent to a newer ExprTrait::lte and may require more some wrapping beforehand.
ยงExamples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where(Expr::col((Char::Table, Char::SizeW)).lte(2))
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"SELECT `character`, `size_w`, `size_h` FROM `character` WHERE `character`.`size_w` <= 2"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "character"."size_w" <= 2"#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "character"."size_w" <= 2"#
);
sourcepub fn add<V>(self, v: V) -> SimpleExprwhere
V: Into<SimpleExpr>,
pub fn add<V>(self, v: V) -> SimpleExprwhere
V: Into<SimpleExpr>,
Express an arithmetic addition operation.
This is equivalent to a newer ExprTrait::add and may require more some wrapping beforehand.
ยงExamples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where(Expr::val(1).add(1).eq(2))
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"SELECT `character`, `size_w`, `size_h` FROM `character` WHERE 1 + 1 = 2"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE 1 + 1 = 2"#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE 1 + 1 = 2"#
);
sourcepub fn sub<V>(self, v: V) -> SimpleExprwhere
V: Into<SimpleExpr>,
pub fn sub<V>(self, v: V) -> SimpleExprwhere
V: Into<SimpleExpr>,
Express an arithmetic subtraction operation.
This is equivalent to a newer ExprTrait::sub and may require more some wrapping beforehand.
ยงExamples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where(Expr::val(1).sub(1).eq(2))
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"SELECT `character`, `size_w`, `size_h` FROM `character` WHERE 1 - 1 = 2"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE 1 - 1 = 2"#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE 1 - 1 = 2"#
);
sourcepub fn mul<V>(self, v: V) -> SimpleExprwhere
V: Into<SimpleExpr>,
pub fn mul<V>(self, v: V) -> SimpleExprwhere
V: Into<SimpleExpr>,
Express an arithmetic multiplication operation.
This is equivalent to a newer ExprTrait::mul and may require more some wrapping beforehand.
ยงExamples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where(Expr::val(1).mul(1).eq(2))
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"SELECT `character`, `size_w`, `size_h` FROM `character` WHERE 1 * 1 = 2"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE 1 * 1 = 2"#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE 1 * 1 = 2"#
);
sourcepub fn div<V>(self, v: V) -> SimpleExprwhere
V: Into<SimpleExpr>,
pub fn div<V>(self, v: V) -> SimpleExprwhere
V: Into<SimpleExpr>,
Express an arithmetic division operation.
This is equivalent to a newer ExprTrait::div and may require more some wrapping beforehand.
ยงExamples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where(Expr::val(1).div(1).eq(2))
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"SELECT `character`, `size_w`, `size_h` FROM `character` WHERE 1 / 1 = 2"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE 1 / 1 = 2"#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE 1 / 1 = 2"#
);
sourcepub fn modulo<V>(self, v: V) -> SimpleExprwhere
V: Into<SimpleExpr>,
pub fn modulo<V>(self, v: V) -> SimpleExprwhere
V: Into<SimpleExpr>,
Express an arithmetic modulo operation.
This is equivalent to a newer ExprTrait::modulo and may require more some wrapping beforehand.
ยงExamples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where(Expr::val(1).modulo(1).eq(2))
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"SELECT `character`, `size_w`, `size_h` FROM `character` WHERE 1 % 1 = 2"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE 1 % 1 = 2"#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE 1 % 1 = 2"#
);
sourcepub fn left_shift<V>(self, v: V) -> SimpleExprwhere
V: Into<SimpleExpr>,
pub fn left_shift<V>(self, v: V) -> SimpleExprwhere
V: Into<SimpleExpr>,
Express a bitwise left shift.
This is equivalent to a newer ExprTrait::left_shift and may require more some wrapping beforehand.
ยงExamples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where(Expr::val(1).left_shift(1).eq(2))
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"SELECT `character`, `size_w`, `size_h` FROM `character` WHERE 1 << 1 = 2"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE 1 << 1 = 2"#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE 1 << 1 = 2"#
);
sourcepub fn right_shift<V>(self, v: V) -> SimpleExprwhere
V: Into<SimpleExpr>,
pub fn right_shift<V>(self, v: V) -> SimpleExprwhere
V: Into<SimpleExpr>,
Express a bitwise right shift.
This is equivalent to a newer ExprTrait::right_shift and may require more some wrapping beforehand.
ยงExamples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where(Expr::val(1).right_shift(1).eq(2))
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"SELECT `character`, `size_w`, `size_h` FROM `character` WHERE 1 >> 1 = 2"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE 1 >> 1 = 2"#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE 1 >> 1 = 2"#
);
sourcepub fn between<V>(self, a: V, b: V) -> SimpleExprwhere
V: Into<SimpleExpr>,
pub fn between<V>(self, a: V, b: V) -> SimpleExprwhere
V: Into<SimpleExpr>,
Express a BETWEEN
expression.
This is equivalent to a newer ExprTrait::between and may require more some wrapping beforehand.
ยงExamples
use sea_query::{*, tests_cfg::*};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where(Expr::col((Char::Table, Char::SizeW)).between(1, 10))
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"SELECT `character`, `size_w`, `size_h` FROM `character` WHERE `character`.`size_w` BETWEEN 1 AND 10"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "character"."size_w" BETWEEN 1 AND 10"#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "character"."size_w" BETWEEN 1 AND 10"#
);
sourcepub fn not_between<V>(self, a: V, b: V) -> SimpleExprwhere
V: Into<SimpleExpr>,
pub fn not_between<V>(self, a: V, b: V) -> SimpleExprwhere
V: Into<SimpleExpr>,
Express a NOT BETWEEN
expression.
This is equivalent to a newer ExprTrait::not_between and may require more some wrapping beforehand.
ยงExamples
use sea_query::{*, tests_cfg::*};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where(Expr::col((Char::Table, Char::SizeW)).not_between(1, 10))
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"SELECT `character`, `size_w`, `size_h` FROM `character` WHERE `character`.`size_w` NOT BETWEEN 1 AND 10"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "character"."size_w" NOT BETWEEN 1 AND 10"#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "character"."size_w" NOT BETWEEN 1 AND 10"#
);
sourcepub fn like<L: IntoLikeExpr>(self, like: L) -> SimpleExpr
pub fn like<L: IntoLikeExpr>(self, like: L) -> SimpleExpr
Express a LIKE
expression.
This is equivalent to a newer ExprTrait::like and may require more some wrapping beforehand.
ยงExamples
use sea_query::{*, tests_cfg::*};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where(Expr::col((Char::Table, Char::Character)).like("Ours'%"))
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"SELECT `character`, `size_w`, `size_h` FROM `character` WHERE `character`.`character` LIKE 'Ours\'%'"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "character"."character" LIKE E'Ours\'%'"#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "character"."character" LIKE 'Ours''%'"#
);
Like with ESCAPE
use sea_query::{*, tests_cfg::*};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where(Expr::col((Char::Table, Char::Character)).like(LikeExpr::new(r"|_Our|_").escape('|')))
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"SELECT `character`, `size_w`, `size_h` FROM `character` WHERE `character`.`character` LIKE '|_Our|_' ESCAPE '|'"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "character"."character" LIKE '|_Our|_' ESCAPE '|'"#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "character"."character" LIKE '|_Our|_' ESCAPE '|'"#
);
sourcepub fn not_like<L: IntoLikeExpr>(self, like: L) -> SimpleExpr
pub fn not_like<L: IntoLikeExpr>(self, like: L) -> SimpleExpr
Express a NOT LIKE
expression.
This is equivalent to a newer ExprTrait::not_like and may require more some wrapping beforehand.
sourcepub fn is_null(self) -> SimpleExpr
pub fn is_null(self) -> SimpleExpr
Express a IS NULL
expression.
This is equivalent to a newer ExprTrait::is_null and may require more some wrapping beforehand.
ยงExamples
use sea_query::{*, tests_cfg::*};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where(Expr::col((Char::Table, Char::SizeW)).is_null())
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"SELECT `character`, `size_w`, `size_h` FROM `character` WHERE `character`.`size_w` IS NULL"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "character"."size_w" IS NULL"#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "character"."size_w" IS NULL"#
);
sourcepub fn is<V>(self, v: V) -> SimpleExprwhere
V: Into<SimpleExpr>,
pub fn is<V>(self, v: V) -> SimpleExprwhere
V: Into<SimpleExpr>,
Express a IS
expression.
This is equivalent to a newer ExprTrait::is and may require more some wrapping beforehand.
ยงExamples
use sea_query::{*, tests_cfg::*};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where(Expr::col((Char::Table, Char::Ascii)).is(true))
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"SELECT `character`, `size_w`, `size_h` FROM `character` WHERE `character`.`ascii` IS TRUE"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "character"."ascii" IS TRUE"#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "character"."ascii" IS TRUE"#
);
sourcepub fn is_not_null(self) -> SimpleExpr
pub fn is_not_null(self) -> SimpleExpr
Express a IS NOT NULL
expression.
This is equivalent to a newer ExprTrait::is_not_null and may require more some wrapping beforehand.
ยงExamples
use sea_query::{*, tests_cfg::*};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where(Expr::col((Char::Table, Char::SizeW)).is_not_null())
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"SELECT `character`, `size_w`, `size_h` FROM `character` WHERE `character`.`size_w` IS NOT NULL"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "character"."size_w" IS NOT NULL"#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "character"."size_w" IS NOT NULL"#
);
sourcepub fn is_not<V>(self, v: V) -> SimpleExprwhere
V: Into<SimpleExpr>,
pub fn is_not<V>(self, v: V) -> SimpleExprwhere
V: Into<SimpleExpr>,
Express a IS NOT
expression.
This is equivalent to a newer ExprTrait::is_not and may require more some wrapping beforehand.
ยงExamples
use sea_query::{*, tests_cfg::*};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where(Expr::col((Char::Table, Char::Ascii)).is_not(true))
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"SELECT `character`, `size_w`, `size_h` FROM `character` WHERE `character`.`ascii` IS NOT TRUE"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "character"."ascii" IS NOT TRUE"#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "character"."ascii" IS NOT TRUE"#
);
sourcepub fn binary<O, T>(self, op: O, right: T) -> SimpleExpr
pub fn binary<O, T>(self, op: O, right: T) -> SimpleExpr
Create any binary operation
This is equivalent to a newer ExprTrait::binary and may require more some wrapping beforehand.
ยงExamples
use sea_query::{*, tests_cfg::*};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.cond_where(all![
Expr::col(Char::SizeW).binary(BinOper::SmallerThan, 10),
Expr::col(Char::SizeW).binary(BinOper::GreaterThan, Expr::col(Char::SizeH))
])
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"SELECT `character`, `size_w`, `size_h` FROM `character` WHERE `size_w` < 10 AND `size_w` > `size_h`"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "size_w" < 10 AND "size_w" > "size_h""#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "size_w" < 10 AND "size_w" > "size_h""#
);
sourcepub fn not(self) -> SimpleExpr
pub fn not(self) -> SimpleExpr
Negates an expression with NOT
.
This is equivalent to a newer ExprTrait::not and may require more some wrapping beforehand.
ยงExamples
use sea_query::{*, tests_cfg::*};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where(Expr::expr(Expr::col((Char::Table, Char::SizeW)).is_null()).not())
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"SELECT `character`, `size_w`, `size_h` FROM `character` WHERE NOT `character`.`size_w` IS NULL"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE NOT "character"."size_w" IS NULL"#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE NOT "character"."size_w" IS NULL"#
);
sourcepub fn max(self) -> SimpleExpr
pub fn max(self) -> SimpleExpr
Express a MAX
function.
ยงExamples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
.expr(Expr::col((Char::Table, Char::SizeW)).max())
.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(self) -> SimpleExpr
pub fn min(self) -> SimpleExpr
Express a MIN
function.
ยงExamples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
.expr(Expr::col((Char::Table, Char::SizeW)).min())
.from(Char::Table)
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"SELECT MIN(`character`.`size_w`) FROM `character`"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT MIN("character"."size_w") FROM "character""#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"SELECT MIN("character"."size_w") FROM "character""#
);
sourcepub fn sum(self) -> SimpleExpr
pub fn sum(self) -> SimpleExpr
Express a SUM
function.
ยงExamples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
.expr(Expr::col((Char::Table, Char::SizeW)).sum())
.from(Char::Table)
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"SELECT SUM(`character`.`size_w`) FROM `character`"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT SUM("character"."size_w") FROM "character""#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"SELECT SUM("character"."size_w") FROM "character""#
);
sourcepub fn count(self) -> SimpleExpr
pub fn count(self) -> SimpleExpr
Express a COUNT
function.
ยงExamples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
.expr(Expr::col((Char::Table, Char::SizeW)).count())
.from(Char::Table)
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"SELECT COUNT(`character`.`size_w`) FROM `character`"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT COUNT("character"."size_w") FROM "character""#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"SELECT COUNT("character"."size_w") FROM "character""#
);
sourcepub fn count_distinct(self) -> SimpleExpr
pub fn count_distinct(self) -> SimpleExpr
Express a COUNT
function with the DISTINCT modifier.
ยงExamples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
.expr(Expr::col((Char::Table, Char::SizeW)).count_distinct())
.from(Char::Table)
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"SELECT COUNT(DISTINCT `character`.`size_w`) FROM `character`"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT COUNT(DISTINCT "character"."size_w") FROM "character""#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"SELECT COUNT(DISTINCT "character"."size_w") FROM "character""#
);
sourcepub fn if_null<V>(self, v: V) -> SimpleExprwhere
V: Into<SimpleExpr>,
pub fn if_null<V>(self, v: V) -> SimpleExprwhere
V: Into<SimpleExpr>,
Express a IF NULL
function.
ยงExamples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
.expr(Expr::col((Char::Table, Char::SizeW)).if_null(0))
.from(Char::Table)
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"SELECT IFNULL(`character`.`size_w`, 0) FROM `character`"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT COALESCE("character"."size_w", 0) FROM "character""#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"SELECT IFNULL("character"."size_w", 0) FROM "character""#
);
sourcepub fn is_in<V, I>(self, v: I) -> SimpleExpr
pub fn is_in<V, I>(self, v: I) -> SimpleExpr
Express a IN
expression.
This is equivalent to a newer ExprTrait::is_in and may require more some wrapping beforehand.
ยงExamples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
.columns([Char::Id])
.from(Char::Table)
.and_where(Expr::col((Char::Table, Char::SizeW)).is_in([1, 2, 3]))
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"SELECT `id` FROM `character` WHERE `character`.`size_w` IN (1, 2, 3)"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT "id" FROM "character" WHERE "character"."size_w" IN (1, 2, 3)"#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"SELECT "id" FROM "character" WHERE "character"."size_w" IN (1, 2, 3)"#
);
Empty value list
use sea_query::{tests_cfg::*, *};
let query = Query::select()
.columns([Char::Id])
.from(Char::Table)
.and_where(Expr::col((Char::Table, Char::SizeW)).is_in(Vec::<u8>::new()))
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"SELECT `id` FROM `character` WHERE 1 = 2"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT "id" FROM "character" WHERE 1 = 2"#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"SELECT "id" FROM "character" WHERE 1 = 2"#
);
sourcepub fn in_tuples<V, I>(self, v: I) -> SimpleExprwhere
V: IntoValueTuple,
I: IntoIterator<Item = V>,
pub fn in_tuples<V, I>(self, v: I) -> SimpleExprwhere
V: IntoValueTuple,
I: IntoIterator<Item = V>,
Express a IN
sub expression.
This is equivalent to a newer ExprTrait::in_tuples and may require more some wrapping beforehand.
ยงExamples
use sea_query::{*, tests_cfg::*};
let query = Query::select()
.columns([Char::Character, Char::FontId])
.from(Char::Table)
.and_where(
Expr::tuple([
Expr::col(Char::Character).into(),
Expr::col(Char::FontId).into(),
])
.in_tuples([(1, String::from("1")), (2, String::from("2"))])
)
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"SELECT `character`, `font_id` FROM `character` WHERE (`character`, `font_id`) IN ((1, '1'), (2, '2'))"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT "character", "font_id" FROM "character" WHERE ("character", "font_id") IN ((1, '1'), (2, '2'))"#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"SELECT "character", "font_id" FROM "character" WHERE ("character", "font_id") IN ((1, '1'), (2, '2'))"#
);
sourcepub fn is_not_in<V, I>(self, v: I) -> SimpleExpr
pub fn is_not_in<V, I>(self, v: I) -> SimpleExpr
Express a NOT IN
expression.
This is equivalent to a newer ExprTrait::is_not_in and may require more some wrapping beforehand.
ยงExamples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
.columns([Char::Id])
.from(Char::Table)
.and_where(Expr::col((Char::Table, Char::SizeW)).is_not_in([1, 2, 3]))
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"SELECT `id` FROM `character` WHERE `character`.`size_w` NOT IN (1, 2, 3)"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT "id" FROM "character" WHERE "character"."size_w" NOT IN (1, 2, 3)"#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"SELECT "id" FROM "character" WHERE "character"."size_w" NOT IN (1, 2, 3)"#
);
Empty value list
use sea_query::{tests_cfg::*, *};
let query = Query::select()
.columns([Char::Id])
.from(Char::Table)
.and_where(Expr::col((Char::Table, Char::SizeW)).is_not_in(Vec::<u8>::new()))
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"SELECT `id` FROM `character` WHERE 1 = 1"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT "id" FROM "character" WHERE 1 = 1"#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"SELECT "id" FROM "character" WHERE 1 = 1"#
);
sourcepub fn in_subquery(self, sel: SelectStatement) -> SimpleExpr
pub fn in_subquery(self, sel: SelectStatement) -> SimpleExpr
Express a IN
sub-query expression.
This is equivalent to a newer ExprTrait::in_subquery and may require more some wrapping beforehand.
ยงExamples
use sea_query::{*, tests_cfg::*};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where(Expr::col(Char::SizeW).in_subquery(
Query::select()
.expr(Expr::cust("3 + 2 * 2"))
.take()
))
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"SELECT `character`, `size_w`, `size_h` FROM `character` WHERE `size_w` IN (SELECT 3 + 2 * 2)"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "size_w" IN (SELECT 3 + 2 * 2)"#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "size_w" IN (SELECT 3 + 2 * 2)"#
);
sourcepub fn not_in_subquery(self, sel: SelectStatement) -> SimpleExpr
pub fn not_in_subquery(self, sel: SelectStatement) -> SimpleExpr
Express a NOT IN
sub-query expression.
This is equivalent to a newer ExprTrait::not_in_subquery and may require more some wrapping beforehand.
ยงExamples
use sea_query::{*, tests_cfg::*};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where(Expr::col(Char::SizeW).not_in_subquery(
Query::select()
.expr(Expr::cust("3 + 2 * 2"))
.take()
))
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"SELECT `character`, `size_w`, `size_h` FROM `character` WHERE `size_w` NOT IN (SELECT 3 + 2 * 2)"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "size_w" NOT IN (SELECT 3 + 2 * 2)"#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "size_w" NOT IN (SELECT 3 + 2 * 2)"#
);
sourcepub fn exists(sel: SelectStatement) -> SimpleExpr
pub fn exists(sel: SelectStatement) -> SimpleExpr
Express a EXISTS
sub-query expression.
ยงExamples
use sea_query::{*, tests_cfg::*};
let query = Query::select()
.expr_as(Expr::exists(Query::select().column(Char::Id).from(Char::Table).take()), Alias::new("character_exists"))
.expr_as(Expr::exists(Query::select().column(Glyph::Id).from(Glyph::Table).take()), Alias::new("glyph_exists"))
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"SELECT EXISTS(SELECT `id` FROM `character`) AS `character_exists`, EXISTS(SELECT `id` FROM `glyph`) AS `glyph_exists`"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT EXISTS(SELECT "id" FROM "character") AS "character_exists", EXISTS(SELECT "id" FROM "glyph") AS "glyph_exists""#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"SELECT EXISTS(SELECT "id" FROM "character") AS "character_exists", EXISTS(SELECT "id" FROM "glyph") AS "glyph_exists""#
);
sourcepub fn any(sel: SelectStatement) -> SimpleExpr
pub fn any(sel: SelectStatement) -> SimpleExpr
Express a ANY
sub-query expression.
ยงExamples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
.column(Char::Id)
.from(Char::Table)
.and_where(Expr::col(Char::Id).eq(Expr::any(
Query::select().column(Char::Id).from(Char::Table).take(),
)))
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"SELECT `id` FROM `character` WHERE `id` = ANY(SELECT `id` FROM `character`)"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT "id" FROM "character" WHERE "id" = ANY(SELECT "id" FROM "character")"#
);
sourcepub fn some(sel: SelectStatement) -> SimpleExpr
pub fn some(sel: SelectStatement) -> SimpleExpr
Express a SOME
sub-query expression.
ยงExamples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
.column(Char::Id)
.from(Char::Table)
.and_where(Expr::col(Char::Id).ne(Expr::some(
Query::select().column(Char::Id).from(Char::Table).take(),
)))
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"SELECT `id` FROM `character` WHERE `id` <> SOME(SELECT `id` FROM `character`)"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT "id" FROM "character" WHERE "id" <> SOME(SELECT "id" FROM "character")"#
);
sourcepub fn all(sel: SelectStatement) -> SimpleExpr
pub fn all(sel: SelectStatement) -> SimpleExpr
Express a ALL
sub-query expression.
sourcepub fn as_enum<T>(self, type_name: T) -> SimpleExprwhere
T: IntoIden,
pub fn as_enum<T>(self, type_name: T) -> SimpleExprwhere
T: IntoIden,
Express a AS enum
expression.
This is equivalent to a newer ExprTrait::as_enum and may require more some wrapping beforehand.
ยงExamples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
.expr(Expr::col(Char::FontSize).as_enum(Alias::new("text")))
.from(Char::Table)
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"SELECT `font_size` FROM `character`"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT CAST("font_size" AS text) FROM "character""#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"SELECT "font_size" FROM "character""#
);
let query = Query::insert()
.into_table(Char::Table)
.columns([Char::FontSize])
.values_panic([Expr::val("large").as_enum(Alias::new("FontSizeEnum"))])
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"INSERT INTO `character` (`font_size`) VALUES ('large')"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"INSERT INTO "character" ("font_size") VALUES (CAST('large' AS FontSizeEnum))"#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"INSERT INTO "character" ("font_size") VALUES ('large')"#
);
sourcepub fn case<C, T>(cond: C, then: T) -> CaseStatement
pub fn case<C, T>(cond: C, then: T) -> CaseStatement
Adds new CASE WHEN
to existing case statement.
ยงExamples
use sea_query::{*, tests_cfg::*};
let query = Query::select()
.expr_as(
Expr::case(
Expr::col((Glyph::Table, Glyph::Aspect)).is_in([2, 4]),
true
)
.finally(false),
Alias::new("is_even")
)
.from(Glyph::Table)
.to_owned();
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT (CASE WHEN ("glyph"."aspect" IN (2, 4)) THEN TRUE ELSE FALSE END) AS "is_even" FROM "glyph""#
);
sourcepub fn cast_as<T>(self, type_name: T) -> SimpleExprwhere
T: IntoIden,
pub fn cast_as<T>(self, type_name: T) -> SimpleExprwhere
T: IntoIden,
Express a CAST AS
expression.
This is equivalent to a newer ExprTrait::cast_as and may require more some wrapping beforehand.
ยงExamples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
.expr(Expr::val("1").cast_as(Alias::new("integer")))
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"SELECT CAST('1' AS integer)"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT CAST('1' AS integer)"#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"SELECT CAST('1' AS integer)"#
);
sourcepub fn current_date() -> Expr
pub fn current_date() -> Expr
Keyword CURRENT_DATE
.
ยงExamples
use sea_query::*;
let query = Query::select().expr(Expr::current_date()).to_owned();
assert_eq!(query.to_string(MysqlQueryBuilder), r#"SELECT CURRENT_DATE"#);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT CURRENT_DATE"#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"SELECT CURRENT_DATE"#
);
sourcepub fn current_time() -> Expr
pub fn current_time() -> Expr
Keyword CURRENT_TIMESTAMP
.
ยงExamples
use sea_query::*;
let query = Query::select().expr(Expr::current_time()).to_owned();
assert_eq!(query.to_string(MysqlQueryBuilder), r#"SELECT CURRENT_TIME"#);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT CURRENT_TIME"#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"SELECT CURRENT_TIME"#
);
sourcepub fn current_timestamp() -> Expr
pub fn current_timestamp() -> Expr
Keyword CURRENT_TIMESTAMP
.
ยงExamples
use sea_query::{Expr, MysqlQueryBuilder, PostgresQueryBuilder, Query, SqliteQueryBuilder};
let query = Query::select().expr(Expr::current_timestamp()).to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"SELECT CURRENT_TIMESTAMP"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT CURRENT_TIMESTAMP"#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"SELECT CURRENT_TIMESTAMP"#
);
sourcepub fn custom_keyword<T>(i: T) -> Exprwhere
T: IntoIden,
pub fn custom_keyword<T>(i: T) -> Exprwhere
T: IntoIden,
Custom keyword.
ยงExamples
use sea_query::*;
let query = Query::select()
.expr(Expr::custom_keyword(Alias::new("test")))
.to_owned();
assert_eq!(query.to_string(MysqlQueryBuilder), r#"SELECT test"#);
assert_eq!(query.to_string(PostgresQueryBuilder), r#"SELECT test"#);
assert_eq!(query.to_string(SqliteQueryBuilder), r#"SELECT test"#);
Trait Implementationsยง
sourceยงimpl PgExpr for Expr
Available on crate feature backend-postgres
only.
impl PgExpr for Expr
backend-postgres
only.sourceยงfn concatenate<T>(self, right: T) -> SimpleExprwhere
T: Into<SimpleExpr>,
fn concatenate<T>(self, right: T) -> SimpleExprwhere
T: Into<SimpleExpr>,
||
) expression. Read moresourceยงfn concat<T>(self, right: T) -> SimpleExprwhere
T: Into<SimpleExpr>,
fn concat<T>(self, right: T) -> SimpleExprwhere
T: Into<SimpleExpr>,
PgExpr::concatenate
sourceยงfn matches<T>(self, expr: T) -> SimpleExprwhere
T: Into<SimpleExpr>,
fn matches<T>(self, expr: T) -> SimpleExprwhere
T: Into<SimpleExpr>,
@@
) expression. Read moresourceยงfn contains<T>(self, expr: T) -> SimpleExprwhere
T: Into<SimpleExpr>,
fn contains<T>(self, expr: T) -> SimpleExprwhere
T: Into<SimpleExpr>,
@>
) expression. Read moresourceยงfn contained<T>(self, expr: T) -> SimpleExprwhere
T: Into<SimpleExpr>,
fn contained<T>(self, expr: T) -> SimpleExprwhere
T: Into<SimpleExpr>,
<@
) expression. Read moresourceยงfn ilike<L>(self, like: L) -> SimpleExprwhere
L: IntoLikeExpr,
fn ilike<L>(self, like: L) -> SimpleExprwhere
L: IntoLikeExpr,
ILIKE
expression. Read moresourceยงfn not_ilike<L>(self, like: L) -> SimpleExprwhere
L: IntoLikeExpr,
fn not_ilike<L>(self, like: L) -> SimpleExprwhere
L: IntoLikeExpr,
NOT ILIKE
expressionsourceยงfn get_json_field<T>(self, right: T) -> SimpleExprwhere
T: Into<SimpleExpr>,
fn get_json_field<T>(self, right: T) -> SimpleExprwhere
T: Into<SimpleExpr>,
->
). Read moresourceยงfn cast_json_field<T>(self, right: T) -> SimpleExprwhere
T: Into<SimpleExpr>,
fn cast_json_field<T>(self, right: T) -> SimpleExprwhere
T: Into<SimpleExpr>,
->>
). Read moresourceยงimpl SqliteExpr for Expr
Available on crate feature backend-sqlite
only.
impl SqliteExpr for Expr
backend-sqlite
only.sourceยงfn glob<T>(self, right: T) -> SimpleExprwhere
T: Into<SimpleExpr>,
fn glob<T>(self, right: T) -> SimpleExprwhere
T: Into<SimpleExpr>,
GLOB
operator. Read moresourceยงfn matches<T>(self, right: T) -> SimpleExprwhere
T: Into<SimpleExpr>,
fn matches<T>(self, right: T) -> SimpleExprwhere
T: Into<SimpleExpr>,
MATCH
operator. Read moresourceยงfn get_json_field<T>(self, right: T) -> SimpleExprwhere
T: Into<SimpleExpr>,
fn get_json_field<T>(self, right: T) -> SimpleExprwhere
T: Into<SimpleExpr>,
->
). Read moresourceยงfn cast_json_field<T>(self, right: T) -> SimpleExprwhere
T: Into<SimpleExpr>,
fn cast_json_field<T>(self, right: T) -> SimpleExprwhere
T: Into<SimpleExpr>,
->>
). Read moreAuto Trait Implementationsยง
impl Freeze for Expr
impl !RefUnwindSafe for Expr
impl Send for Expr
impl Sync for Expr
impl Unpin for Expr
impl !UnwindSafe for Expr
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
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)
clone_to_uninit
)sourceยงimpl<T> ExprTrait for Twhere
T: Into<SimpleExpr>,
impl<T> ExprTrait for Twhere
T: Into<SimpleExpr>,
sourceยงfn as_enum<N>(self, type_name: N) -> SimpleExprwhere
N: IntoIden,
fn as_enum<N>(self, type_name: N) -> SimpleExprwhere
N: IntoIden,
AS enum
expression. Read moresourceยงfn binary<O, R>(self, op: O, right: R) -> SimpleExpr
fn binary<O, R>(self, op: O, right: R) -> SimpleExpr
sourceยงfn cast_as<N>(self, type_name: N) -> SimpleExprwhere
N: IntoIden,
fn cast_as<N>(self, type_name: N) -> SimpleExprwhere
N: IntoIden,
CAST AS
expression. Read moresourceยงfn unary(self, op: UnOper) -> SimpleExpr
fn unary(self, op: UnOper) -> SimpleExpr
sourceยงfn add<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn add<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn and<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
sourceยงfn between<A, B>(self, a: A, b: B) -> SimpleExpr
fn between<A, B>(self, a: A, b: B) -> SimpleExpr
BETWEEN
expression. Read moresourceยงfn div<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn div<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
sourceยงfn eq<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn eq<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
=
) expression. Read moresourceยงfn equals<C>(self, col: C) -> SimpleExprwhere
C: IntoColumnRef,
fn equals<C>(self, col: C) -> SimpleExprwhere
C: IntoColumnRef,
sourceยงfn gt<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn gt<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
>
) expression. Read moresourceยงfn gte<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn gte<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
>=
) expression. Read moresourceยงfn in_subquery(self, sel: SelectStatement) -> SimpleExpr
fn in_subquery(self, sel: SelectStatement) -> SimpleExpr
IN
sub-query expression. Read moresourceยงfn in_tuples<V, I>(self, v: I) -> SimpleExprwhere
V: IntoValueTuple,
I: IntoIterator<Item = V>,
fn in_tuples<V, I>(self, v: I) -> SimpleExprwhere
V: IntoValueTuple,
I: IntoIterator<Item = V>,
IN
sub expression. Read moresourceยงfn is<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn is<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
IS
expression. Read moresourceยงfn is_in<V, I>(self, v: I) -> SimpleExpr
fn is_in<V, I>(self, v: I) -> SimpleExpr
IN
expression. Read moresourceยงfn is_not<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn is_not<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
IS NOT
expression. Read moresourceยงfn is_not_in<V, I>(self, v: I) -> SimpleExpr
fn is_not_in<V, I>(self, v: I) -> SimpleExpr
NOT IN
expression. Read moresourceยงfn is_not_null(self) -> SimpleExpr
fn is_not_null(self) -> SimpleExpr
IS NOT NULL
expression. Read moresourceยงfn is_null(self) -> SimpleExpr
fn is_null(self) -> SimpleExpr
IS NULL
expression. Read moresourceยงfn left_shift<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn left_shift<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
sourceยงfn like<L>(self, like: L) -> SimpleExprwhere
L: IntoLikeExpr,
fn like<L>(self, like: L) -> SimpleExprwhere
L: IntoLikeExpr,
LIKE
expression. Read moresourceยงfn lt<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn lt<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
<
) expression. Read moresourceยงfn lte<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn lte<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
<=
) expression. Read moresourceยงfn modulo<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn modulo<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
sourceยงfn mul<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn mul<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
sourceยงfn ne<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn ne<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
<>
) expression. Read moresourceยงfn not(self) -> SimpleExpr
fn not(self) -> SimpleExpr
NOT
. Read moresourceยงfn not_between<A, B>(self, a: A, b: B) -> SimpleExpr
fn not_between<A, B>(self, a: A, b: B) -> SimpleExpr
NOT BETWEEN
expression. Read moresourceยงfn not_equals<C>(self, col: C) -> SimpleExprwhere
C: IntoColumnRef,
fn not_equals<C>(self, col: C) -> SimpleExprwhere
C: IntoColumnRef,
sourceยงfn not_in_subquery(self, sel: SelectStatement) -> SimpleExpr
fn not_in_subquery(self, sel: SelectStatement) -> SimpleExpr
NOT IN
sub-query expression. Read moresourceยงfn not_like<L>(self, like: L) -> SimpleExprwhere
L: IntoLikeExpr,
fn not_like<L>(self, like: L) -> SimpleExprwhere
L: IntoLikeExpr,
NOT LIKE
expression. Read moresourceยงfn or<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn or<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
OR
operation. Read more