sqlx
sqlx copied to clipboard
Transparent tuple struct not working within FromRow + Option
I'm using a FromRow from my main model structure:
#[derive(sqlx::FromRow)]
struct MyUser {
email: Option<Email>,
}
With my Email being defined like shown, similar to the docs:
#[derive(sqlx::Type)]
#[sqlx(transparent)]
pub struct Email(String);
I run a sqlx::query_as!(MyUser, ..) database transaction:
sqlx::query_as!(MyUser, "SELECT * FROM my_user WHERE id=$1", id).await?;
But when I try to run this, I get presented with ^ expected struct Email, found struct std::string::String. For some reason, I don't think query_as knows how to convert from Option<String> to Option<Email> even though it's defined as a transparent type. I've tried implementing FromRow manually to bypass the derive and proc macro but I get the same error.