The trait `FromSql<'_>` is not implemented for `Uuid` in tokio-postgres in rust

1.8k views Asked by At

I am trying to use UUID as my primary key in Postgres.
I am getting the trait FromSql<'_> is not implemented for Uuid in tokio-postgres.

First I try to use tokio-pg-mapper but it is also showing the same compile error.

So, I try diff approach and try to implement the From on Struct to covert it directly from Row.

When I try to implements From to convert the Row type to my struct 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")
       }
    }
}

Still getting the the trait FromSql<'_> is not implemented for Uuid in tokio-postgres

I know that it is asking me to implement the FromSql for the UUID type.
But I looked into the tokio-postgres docs and found that it is already implemented there.

Did I miss something ?

uuid=0.8
tokio-postgres=0.7.2

1

There are 1 answers

0
GrvTyagi On BEST ANSWER

To activate the UUID support I need to declare it in my Cargo.toml file and it will start working with tokio-pg-mapper and with my custom solution too.

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