Skip to content

Commit 6a251ef

Browse files
committed
fix(mysql): enum type derive and column overrides need to deref before eq
1 parent d209c60 commit 6a251ef

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

sqlx-macros/src/derives/type.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ fn expand_derive_has_sql_type_strong_enum(
135135
}
136136

137137
fn compatible(ty: &sqlx::mysql::MySqlTypeInfo) -> bool {
138-
ty == sqlx::mysql::MySqlTypeInfo::__enum()
138+
*ty == sqlx::mysql::MySqlTypeInfo::__enum()
139139
}
140140
}
141141
));

tests/mysql/macros.rs

+21
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,14 @@ async fn test_column_override_nullable() -> anyhow::Result<()> {
124124
#[sqlx(transparent)]
125125
struct MyInt4(i32);
126126

127+
#[derive(PartialEq, Eq, Debug, sqlx::Type)]
128+
#[sqlx(rename_all = "lowercase")]
129+
enum MyEnum {
130+
Red,
131+
Green,
132+
Blue,
133+
}
134+
127135
#[sqlx_macros::test]
128136
async fn test_column_override_wildcard() -> anyhow::Result<()> {
129137
struct Record {
@@ -154,4 +162,17 @@ async fn test_column_override_exact() -> anyhow::Result<()> {
154162
Ok(())
155163
}
156164

165+
#[sqlx_macros::test]
166+
async fn test_column_override_exact_enum() -> anyhow::Result<()> {
167+
let mut conn = new::<MySql>().await?;
168+
169+
let record = sqlx::query!("select * from (select 'red' as `color: MyEnum`) records")
170+
.fetch_one(&mut conn)
171+
.await?;
172+
173+
assert_eq!(record.color, MyEnum::Red);
174+
175+
Ok(())
176+
}
177+
157178
// we don't emit bind parameter typechecks for MySQL so testing the overrides is redundant

0 commit comments

Comments
 (0)