error[E0277]: the trait bound `Struct: std::convert::From<()>` is not satisfied
I have found these related issues/pull requests
none
Description
Here is my rust code:
#[derive(Debug, Deserialize, Serialize, sqlx::Type, ToSchema)]
#[sqlx(type_name = "user_class_enum")]
pub enum UserClass {
#[sqlx(rename = "newbie")]
#[serde(rename = "newbie")]
Newbie,
#[sqlx(rename = "staff")]
#[serde(rename = "staff")]
Staff,
}
#[derive(Debug, Serialize, Deserialize, FromRow, ToSchema)]
pub struct User {
pub id: i64,
pub class: UserClass
}
sqlx::query_as!(
User,
r#"
SELECT * FROM users
WHERE id = $1
"#,
id
)
.fetch_one(pool)
.await
.map_err(|_| Error::WrongUsernameOrPassword)
Here is the SQL (pgsql db):
CREATE TYPE user_class_enum AS ENUM (
'newbie',
'staff'
);
CREATE TABLE users (
id BIGSERIAL PRIMARY KEY,
class user_class_enum NOT NULL DEFAULT 'newbie'
);
I am getting this compiler error:
error[E0277]: the trait bound UserClass: std::convert::From<()> is not satisfied
Reproduction steps
run the code from above
SQLx version
0.8
Enabled SQLx features
"runtime-async-std", "postgres", "chrono", "ipnetwork",
Database server and version
Postgresql 17.4 (running in docker)
Operating system
Asahi Linux
Rust version
1.86.0
The macro's don't know about your custom enum UserClass, you can override the inferred type with the type override syntax. E.g. SELECT id, class as "class: UserClass" FROM ...
The macro's don't know about your custom enum
UserClass, you can override the inferred type with the type override syntax. E.g.SELECT id, class as "class: UserClass" FROM ...
I feel like sqlx should know with the annotation matching the SQL enum. Or what is the annotation for then ?