use crate::utils::aliases::ADb;
use sea_query::{Alias, Expr, ExprTrait, Func};
pub fn text_cast_type(db: &ADb) -> &'static str {
text_cast_type_of(db.get_database_backend())
}
pub fn text_cast_type_of(backend: sea_orm::DbBackend) -> &'static str {
match backend {
sea_orm::DbBackend::MySql => "CHAR",
_ => "TEXT",
}
}
pub fn text_eq(db: &ADb, col: &str, val: &str) -> Expr {
Expr::col(Alias::new(col))
.cast_as(Alias::new(text_cast_type(db)))
.eq(val)
}
pub fn text_eq_ci(db: &ADb, col: &str, val: &str) -> Expr {
Expr::expr(Func::lower(
Expr::col(Alias::new(col)).cast_as(Alias::new(text_cast_type(db))),
))
.eq(Func::lower(Expr::val(val)))
}
pub fn ilike(db: &ADb, col: &str, pattern: &str) -> Expr {
Expr::expr(Func::lower(
Expr::col(Alias::new(col)).cast_as(Alias::new(text_cast_type(db))),
))
.like(pattern)
}