I want to query a field using MySQLs "SOUNDS LIKE".
SQL:
WHERE field SOUNDS LIKE "blah"
How to query this with diesel framework?
I thought of
.filter(sql("field SOUNDS LIKE ???"))
But how to inject (bind()
) my value here with correct escaping?
Or is there a better way to filter using unsupported SQL?
EDIT1:
I found the infix_operator macro but it doesn't work. SqlType
, TypedExpressionType
and infix_operator macro is not found. But according to Github it's exactly there:
use diesel::sql_types::SqlType;
use diesel::expression::TypedExpressionType;
use diesel::expression::AsExpression;
use diesel::expression::Expression;
diesel::infix_operator!(SoundsLike, " SOUNDS LIKE ");
fn sounds_like<T, U, ST>(left: T, right: U) -> SoundsLike<T, U::Expression>
where
T: Expression<SqlType = ST>,
U: AsExpression<ST>,
ST: SqlType + TypedExpressionType,
{
SoundsLike::new(left, right.as_expression())
}
question from:
https://stackoverflow.com/questions/66066750/sounds-like-in-diesel-query 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…