gpt4 book ai didi

mysql - 柴油查询中的"SOUNDS LIKE"

转载 作者:行者123 更新时间:2023-12-03 11:34:42 26 4
gpt4 key购买 nike

我想使用 MySQL 的“SOUNDS LIKE”查询一个字段。
SQL:

WHERE field SOUNDS LIKE "blah"
如何用柴油框架查询这个?
我想到了
.filter(sql("field SOUNDS LIKE ???"))
但是如何通过正确的转义在这里注入(inject)( bind())我的值?
或者有没有更好的方法来使用不受支持的 SQL 进行过滤?
EDIT1:
我找到了 infix_operator 宏,但它不起作用。 SqlType , TypedExpressionType并且找不到 infix_operator 宏。但根据 Github,它就在那里:
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())
}

最佳答案

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:


那是因为您查看了包含未发布更改的主分支。其中之一是 diesel::infix_operator! 的重命名。来自 diesel_infix_operator!
通过使用最新版本的变体,您的代码应该可以正常工作:
#[macro_use] extern crate diesel;

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>,
{
SoundsLike::new(left, right.as_expression())
}

关于mysql - 柴油查询中的"SOUNDS LIKE",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66066750/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com