pub trait ExprTrait: Sized {
Show 35 methods
// Required methods
fn as_enum<N>(self, type_name: N) -> SimpleExpr
where N: IntoIden;
fn binary<O, R>(self, op: O, right: R) -> SimpleExpr
where O: Into<BinOper>,
R: Into<SimpleExpr>;
fn cast_as<N>(self, type_name: N) -> SimpleExpr
where N: IntoIden;
fn unary(self, o: UnOper) -> SimpleExpr;
// Provided methods
fn add<R>(self, right: R) -> SimpleExpr
where R: Into<SimpleExpr> { ... }
fn and<R>(self, right: R) -> SimpleExpr
where R: Into<SimpleExpr> { ... }
fn between<A, B>(self, a: A, b: B) -> SimpleExpr
where A: Into<SimpleExpr>,
B: Into<SimpleExpr> { ... }
fn div<R>(self, right: R) -> SimpleExpr
where R: Into<SimpleExpr> { ... }
fn eq<R>(self, right: R) -> SimpleExpr
where R: Into<SimpleExpr> { ... }
fn equals<C>(self, col: C) -> SimpleExpr
where C: IntoColumnRef { ... }
fn gt<R>(self, right: R) -> SimpleExpr
where R: Into<SimpleExpr> { ... }
fn gte<R>(self, right: R) -> SimpleExpr
where R: Into<SimpleExpr> { ... }
fn in_subquery(self, sel: SelectStatement) -> SimpleExpr { ... }
fn in_tuples<V, I>(self, v: I) -> SimpleExpr
where V: IntoValueTuple,
I: IntoIterator<Item = V> { ... }
fn is<R>(self, right: R) -> SimpleExpr
where R: Into<SimpleExpr> { ... }
fn is_in<V, I>(self, v: I) -> SimpleExpr
where V: Into<SimpleExpr>,
I: IntoIterator<Item = V> { ... }
fn is_not<R>(self, right: R) -> SimpleExpr
where R: Into<SimpleExpr> { ... }
fn is_not_in<V, I>(self, v: I) -> SimpleExpr
where V: Into<SimpleExpr>,
I: IntoIterator<Item = V> { ... }
fn is_not_null(self) -> SimpleExpr { ... }
fn is_null(self) -> SimpleExpr { ... }
fn left_shift<R>(self, right: R) -> SimpleExpr
where R: Into<SimpleExpr> { ... }
fn like<L>(self, like: L) -> SimpleExpr
where L: IntoLikeExpr { ... }
fn lt<R>(self, right: R) -> SimpleExpr
where R: Into<SimpleExpr> { ... }
fn lte<R>(self, right: R) -> SimpleExpr
where R: Into<SimpleExpr> { ... }
fn modulo<R>(self, right: R) -> SimpleExpr
where R: Into<SimpleExpr> { ... }
fn mul<R>(self, right: R) -> SimpleExpr
where R: Into<SimpleExpr> { ... }
fn ne<R>(self, right: R) -> SimpleExpr
where R: Into<SimpleExpr> { ... }
fn not(self) -> SimpleExpr { ... }
fn not_between<A, B>(self, a: A, b: B) -> SimpleExpr
where A: Into<SimpleExpr>,
B: Into<SimpleExpr> { ... }
fn not_equals<C>(self, col: C) -> SimpleExpr
where C: IntoColumnRef { ... }
fn not_in_subquery(self, sel: SelectStatement) -> SimpleExpr { ... }
fn not_like<L>(self, like: L) -> SimpleExpr
where L: IntoLikeExpr { ... }
fn or<R>(self, right: R) -> SimpleExpr
where R: Into<SimpleExpr> { ... }
fn right_shift<R>(self, right: R) -> SimpleExpr
where R: Into<SimpleExpr> { ... }
fn sub<R>(self, right: R) -> SimpleExpr
where R: Into<SimpleExpr> { ... }
}
Expand description
“Operator” methods for building complex expressions.
§Examples
use sea_query::*;
let expr = 1_i32.cast_as(Alias::new("REAL"));
let expr = Func::char_length("abc").eq(3_i32);
let expr = Expr::current_date()
.cast_as(Alias::new("TEXT"))
.like("2024%");
Required Methods§
sourcefn as_enum<N>(self, type_name: N) -> SimpleExprwhere
N: IntoIden,
fn as_enum<N>(self, type_name: N) -> SimpleExprwhere
N: IntoIden,
Express a AS enum
expression.
§Examples
use sea_query::{tests_cfg::*, *};
let query = Query::insert()
.into_table(Char::Table)
.columns([Char::FontSize])
.values_panic(["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')"#
);
sourcefn binary<O, R>(self, op: O, right: R) -> SimpleExpr
fn binary<O, R>(self, op: O, right: R) -> SimpleExpr
Create any binary operation
§Examples
use sea_query::{*, tests_cfg::*};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.cond_where(all![
Char::SizeW.into_column_ref().binary(BinOper::SmallerThan, 10),
Char::SizeW.into_column_ref().binary(BinOper::GreaterThan, Char::SizeH.into_column_ref())
])
.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""#
);
sourcefn cast_as<N>(self, type_name: N) -> SimpleExprwhere
N: IntoIden,
fn cast_as<N>(self, type_name: N) -> SimpleExprwhere
N: IntoIden,
Express a CAST AS
expression.
§Examples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
.expr("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)"#
);
sourcefn unary(self, o: UnOper) -> SimpleExpr
fn unary(self, o: UnOper) -> SimpleExpr
Apply any unary operator to the expression.
§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().unary(UnOper::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"#
);
Provided Methods§
sourcefn add<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn add<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
Express an arithmetic addition operation.
§Examples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where(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"#
);
fn and<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
sourcefn between<A, B>(self, a: A, b: B) -> SimpleExpr
fn between<A, B>(self, a: A, b: B) -> SimpleExpr
Express a BETWEEN
expression.
§Examples
use sea_query::{*, tests_cfg::*};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where((Char::Table, Char::SizeW).into_column_ref().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"#
);
sourcefn div<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn div<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
Express an arithmetic division operation.
§Examples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where(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"#
);
sourcefn eq<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn eq<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
Express an equal (=
) expression.
§Examples
use sea_query::{*, tests_cfg::*};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
// Sometimes, you'll have to qualify the call because of conflicting std traits.
.and_where(ExprTrait::eq("What!", "Nothing"))
.and_where(Char::Id.into_column_ref().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"#
);
sourcefn equals<C>(self, col: C) -> SimpleExprwhere
C: IntoColumnRef,
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.
§Examples
use sea_query::{*, tests_cfg::*};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where((Char::Table, Char::FontId).into_column_ref().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""#
);
sourcefn gt<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn gt<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
Express a greater than (>
) expression.
§Examples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where((Char::Table, Char::SizeW).into_column_ref().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"#
);
sourcefn gte<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn gte<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
Express a greater than or equal (>=
) expression.
§Examples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where((Char::Table, Char::SizeW).into_column_ref().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"#
);
sourcefn in_subquery(self, sel: SelectStatement) -> SimpleExpr
fn in_subquery(self, sel: SelectStatement) -> SimpleExpr
Express a IN
sub-query expression.
§Examples
use sea_query::{*, tests_cfg::*};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where(Char::SizeW.into_column_ref().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)"#
);
sourcefn 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>,
Express a IN
sub expression.
§Examples
use sea_query::{*, tests_cfg::*};
let query = Query::select()
.columns([Char::Character, Char::FontId])
.from(Char::Table)
.and_where(
ExprTrait::in_tuples(
Expr::tuple([
Expr::col(Char::Character).into(),
Expr::col(Char::FontId).into(),
]),
[(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'))"#
);
sourcefn is<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn is<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
Express a IS
expression.
§Examples
use sea_query::{*, tests_cfg::*};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where((Char::Table, Char::Ascii).into_column_ref().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"#
);
sourcefn is_in<V, I>(self, v: I) -> SimpleExpr
fn is_in<V, I>(self, v: I) -> SimpleExpr
Express a IN
expression.
§Examples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
.columns([Char::Id])
.from(Char::Table)
.and_where(
(Char::Table, Char::SizeW)
.into_column_ref()
.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(
(Char::Table, Char::SizeW)
.into_column_ref()
.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"#
);
sourcefn is_not<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn is_not<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
Express a IS NOT
expression.
§Examples
use sea_query::{*, tests_cfg::*};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where((Char::Table, Char::Ascii).into_column_ref().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"#
);
sourcefn is_not_in<V, I>(self, v: I) -> SimpleExpr
fn is_not_in<V, I>(self, v: I) -> SimpleExpr
Express a NOT IN
expression.
§Examples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
.columns([Char::Id])
.from(Char::Table)
.and_where(
(Char::Table, Char::SizeW)
.into_column_ref()
.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(
(Char::Table, Char::SizeW)
.into_column_ref()
.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"#
);
sourcefn is_not_null(self) -> SimpleExpr
fn is_not_null(self) -> SimpleExpr
Express a IS NOT NULL
expression.
§Examples
use sea_query::{*, tests_cfg::*};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where((Char::Table, Char::SizeW).into_column_ref().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"#
);
sourcefn is_null(self) -> SimpleExpr
fn is_null(self) -> SimpleExpr
Express a IS NULL
expression.
§Examples
use sea_query::{*, tests_cfg::*};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where((Char::Table, Char::SizeW).into_column_ref().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"#
);
sourcefn left_shift<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn left_shift<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
Express a bitwise left shift.
§Examples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where(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"#
);
sourcefn like<L>(self, like: L) -> SimpleExprwhere
L: IntoLikeExpr,
fn like<L>(self, like: L) -> SimpleExprwhere
L: IntoLikeExpr,
Express a LIKE
expression.
§Examples
use sea_query::{*, tests_cfg::*};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where((Char::Table, Char::Character).into_column_ref().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((Char::Table, Char::Character).into_column_ref().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 '|'"#
);
sourcefn lt<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn lt<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
Express a less than (<
) expression.
§Examples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where((Char::Table, Char::SizeW).into_column_ref().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"#
);
sourcefn lte<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn lte<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
Express a less than or equal (<=
) expression.
§Examples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where((Char::Table, Char::SizeW).into_column_ref().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"#
);
sourcefn modulo<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn modulo<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
Express an arithmetic modulo operation.
§Examples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where(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"#
);
sourcefn mul<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn mul<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
Express an arithmetic multiplication operation.
§Examples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where(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"#
);
sourcefn ne<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn ne<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
Express a not equal (<>
) expression.
§Examples
use sea_query::{*, tests_cfg::*};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
// Sometimes, you'll have to qualify the call because of conflicting std traits.
.and_where(ExprTrait::ne("Morning", "Good"))
.and_where(Char::Id.into_column_ref().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"#
);
sourcefn not(self) -> SimpleExpr
fn not(self) -> SimpleExpr
Negates an expression with NOT
.
§Examples
use sea_query::{*, tests_cfg::*};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where(ExprTrait::not(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 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"#
);
sourcefn not_between<A, B>(self, a: A, b: B) -> SimpleExpr
fn not_between<A, B>(self, a: A, b: B) -> SimpleExpr
Express a NOT BETWEEN
expression.
§Examples
use sea_query::{*, tests_cfg::*};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where((Char::Table, Char::SizeW).into_column_ref().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"#
);
sourcefn not_equals<C>(self, col: C) -> SimpleExprwhere
C: IntoColumnRef,
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.
§Examples
use sea_query::{*, tests_cfg::*};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where((Char::Table, Char::FontId).into_column_ref().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""#
);
sourcefn not_in_subquery(self, sel: SelectStatement) -> SimpleExpr
fn not_in_subquery(self, sel: SelectStatement) -> SimpleExpr
Express a NOT IN
sub-query expression.
§Examples
use sea_query::{*, tests_cfg::*};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where(Char::SizeW.into_column_ref().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)"#
);
sourcefn not_like<L>(self, like: L) -> SimpleExprwhere
L: IntoLikeExpr,
fn not_like<L>(self, like: L) -> SimpleExprwhere
L: IntoLikeExpr,
Express a NOT LIKE
expression.
§Examples
use sea_query::{*, tests_cfg::*};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where((Char::Table, Char::Character).into_column_ref().not_like("Ours'%"))
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"SELECT `character`, `size_w`, `size_h` FROM `character` WHERE `character`.`character` NOT LIKE 'Ours\'%'"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "character"."character" NOT LIKE E'Ours\'%'"#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE "character"."character" NOT LIKE 'Ours''%'"#
);
sourcefn or<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn or<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
Express a logical OR
operation.
§Examples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where(false.or(true))
.to_owned();
assert_eq!(
query.to_string(MysqlQueryBuilder),
r#"SELECT `character`, `size_w`, `size_h` FROM `character` WHERE FALSE OR TRUE"#
);
assert_eq!(
query.to_string(PostgresQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE FALSE OR TRUE"#
);
assert_eq!(
query.to_string(SqliteQueryBuilder),
r#"SELECT "character", "size_w", "size_h" FROM "character" WHERE FALSE OR TRUE"#
);
sourcefn right_shift<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn right_shift<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
Express a bitwise right shift.
§Examples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where(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"#
);
sourcefn sub<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn sub<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
Express an arithmetic subtraction operation.
§Examples
use sea_query::{tests_cfg::*, *};
let query = Query::select()
.columns([Char::Character, Char::SizeW, Char::SizeH])
.from(Char::Table)
.and_where(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"#
);
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementors§
impl<T> ExprTrait for Twhere
T: Into<SimpleExpr>,
This generic implementation covers all expression types, including ColumnRef, Value, FunctionCall, SimpleExpr…