sea-query
sea-query copied to clipboard
[Feature Request] Allow SimplExpr in like expressions
Motivation
This would allow building dynamic like expressions like this:
fn build_like(expr: Expr, value: sea_query::Value) -> SimpleExpr {
expr.like(Expr::value('%').concat(Expr::value(value)).concat(Expr::value('%')))
}
Hey @DontBreakAlex, intesting! I don't know we can actually do this, select * from posts where title like '%' || 'abc' || '%'
. However, since ||
concat operator only works on Postgres. So, I'm hesitate to allow SimpleExpr
in like expression. Afterall, the so called like expression is a string. So, why not expr.like(format!("%{}%", val))
?
Hi @billy1624, thanks for your interest. The issue is that my external interface accepts Value
s (not Expr::Value
) for all kinds of various filters, and converting it back to a string is a bit barbarous:
expr.like(format!("%{}%",
if let Value::String(str) = str {
if let Some(str) = str { *str } else { "".to_string() }
} else { "".to_string() }
))
This would also allow writing this:
Expr::expr(Func::lower([expr])).like(Func::lower.args([other_expr]))