首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >‘Uuid::Uuid: ToSql<uuid::Uuid,_>`不满意

‘Uuid::Uuid: ToSql<uuid::Uuid,_>`不满意
EN

Stack Overflow用户
提问于 2022-11-29 23:09:11
回答 1查看 23关注 0票数 0

我正在柴油中发布一个原始sql。如果没有参数,代码就会编译。但是,当我使用bind向sql_query添加参数时,代码将不会编译。

代码语言:javascript
复制
    pub fn find(session_id: Uuid) -> Result<Vec<Summary>, CustomError> {
        let q = "select product, sum(price) as price from items where session_id = $1 group by product order by product";
        let mut conn = db::connection()?;
        let item = diesel::sql_query(q)
            //.bind::<Uuid, _>(session_id) <-- won't compile
            .get_results(&mut conn)?;
        Ok(item)
    }

当我添加行.bind::<Uuid, _>(session_id)货物生成失败时

代码语言:javascript
复制
error[E0277]: the trait bound `uuid::Uuid: ToSql<uuid::Uuid, _>` is not satisfied
    --> src/items/models.rs:52:14
     |
52   |             .get_results(&mut conn)?;
     |              ^^^^^^^^^^^ the trait `ToSql<uuid::Uuid, _>` is not implemented for `uuid::Uuid`
     |
     = help: the following other types implement trait `ToSql<A, DB>`:
               <uuid::Uuid as ToSql<Nullable<diesel::sql_types::Uuid>, __DB>>
               <uuid::Uuid as ToSql<diesel::sql_types::Uuid, Pg>>
     = note: required because of the requirements on the impl of `QueryFragment<_>` for `query_builder::sql_query::UncheckedBind<SqlQuery, uuid::Uuid, uuid::Uuid>`
     = note: required because of the requirements on the impl of `LoadQuery<'_, _, _>` for `query_builder::sql_query::UncheckedBind<SqlQuery, uuid::Uuid, uuid::Uuid>`
note: required by a bound in `get_results`
    --> /Users/claus/.cargo/registry/src/github.com-1ecc6299db9ec823/diesel-2.0.2/src/query_dsl/mod.rs:1695:15
     |
1695 |         Self: LoadQuery<'query, Conn, U>,
     |               ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `get_results`

Cargo.toml:

代码语言:javascript
复制
actix-web = "4.2.1"
actix-rt = "2.7.0"
diesel = { version = "2.0.2", features = ["postgres", "r2d2", "uuid", "chrono", "numeric", "serde_json"] }
serde = { version = "1.0.148", features = ["derive"] }
uuid = { version = "1.2.2", features = ["serde", "v4"] }
bigdecimal = { version = "0.3.0", features = ["serde"] }

带有一些绑定示例的柴油车

EN

回答 1

Stack Overflow用户

发布于 2022-11-29 23:12:50

发布后,我尝试更改绑定到diesel::sql_types::Uuid中的Uuid类型。现在代码编译了。所以,如果其他人有类似的问题,就发布一个答案。

代码语言:javascript
复制
.bind::<diesel::sql_types::Uuid, _>(session_id)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74621239

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档