【问题标题】:The trait `FromSql<'_>` is not implemented for `Uuid` in tokio-postgres in rustrust 中的 tokio-postgres 中的 `Uuid` 没有实现特征 `FromSql<'_>`
【发布时间】:2021-10-22 04:21:14
【问题描述】:

我正在尝试使用 UUID 作为我在 Postgres 中的主键。
我得到特征 FromSql&lt;'_&gt; 没有在 tokio-postgres 中为 Uuid 实现

首先我尝试使用tokio-pg-mapper,但它也显示相同的编译错误。

所以,我尝试 diff 方法并尝试在 Struct 上实现 From 以直接从 Row 中转换它。

当我尝试实现From 以将Row 类型转换为我的结构Shop

impl From<Row> for Shop {
    fn from(row: Row) -> Self {
       Self {
            id: row.get("id"), // Id is UUID type
            name: row.get("name"),
            address: row.get("address")
       }
    }
}

仍然得到 特征 FromSql&lt;'_&gt; 未在 tokio-postgres 中为 Uuid 实现

我知道它要求我为 UUID 类型实现 FromSql
但是我查看了tokio-postgresdocs,发现那里已经实现了。

我错过了什么吗?

uuid=0.8
tokio-postgres=0.7.2

【问题讨论】:

    标签: postgresql rust rust-tokio tokio-postgres


    【解决方案1】:

    要激活UUID 支持,我需要在我的Cargo.toml 文件中声明它,它将开始使用tokio-pg-mapper 和我的自定义解决方案。

    tokio-postgres = {version="0.7.2", features=["with-uuid-0_8"]}
    

    【讨论】:

      猜你喜欢
      • 2023-03-29
      • 1970-01-01
      • 1970-01-01
      • 2016-05-29
      • 2022-12-07
      • 1970-01-01
      • 2019-06-13
      • 2022-08-15
      • 2016-06-02
      相关资源
      最近更新 更多