diff --git a/sqlx-macros/src/derives/type.rs b/sqlx-macros/src/derives/type.rs index 127882fb..467e1312 100644 --- a/sqlx-macros/src/derives/type.rs +++ b/sqlx-macros/src/derives/type.rs @@ -135,7 +135,7 @@ fn expand_derive_has_sql_type_strong_enum( } fn compatible(ty: &sqlx::mysql::MySqlTypeInfo) -> bool { - ty == sqlx::mysql::MySqlTypeInfo::__enum() + *ty == sqlx::mysql::MySqlTypeInfo::__enum() } } )); diff --git a/tests/mysql/macros.rs b/tests/mysql/macros.rs index bd259793..0ad54351 100644 --- a/tests/mysql/macros.rs +++ b/tests/mysql/macros.rs @@ -124,6 +124,14 @@ async fn test_column_override_nullable() -> anyhow::Result<()> { #[sqlx(transparent)] struct MyInt4(i32); +#[derive(PartialEq, Eq, Debug, sqlx::Type)] +#[sqlx(rename_all = "lowercase")] +enum MyEnum { + Red, + Green, + Blue, +} + #[sqlx_macros::test] async fn test_column_override_wildcard() -> anyhow::Result<()> { struct Record { @@ -154,4 +162,17 @@ async fn test_column_override_exact() -> anyhow::Result<()> { Ok(()) } +#[sqlx_macros::test] +async fn test_column_override_exact_enum() -> anyhow::Result<()> { + let mut conn = new::().await?; + + let record = sqlx::query!("select * from (select 'red' as `color: MyEnum`) records") + .fetch_one(&mut conn) + .await?; + + assert_eq!(record.color, MyEnum::Red); + + Ok(()) +} + // we don't emit bind parameter typechecks for MySQL so testing the overrides is redundant