Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
koeninger committed Oct 21, 2024
1 parent 028084b commit 2f875ab
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions sqlx-mysql/src/types/uuid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,15 @@ impl Decode<'_, MySql> for Uuid {
// delegate to the &[u8] type to decode from MySQL
let bytes = <&[u8] as Decode<MySql>>::decode(value)?;

// construct a Uuid from the returned bytes
Uuid::from_slice(bytes).map_err(Into::into)
if bytes.len() == 16 {
// construct a Uuid from the returned bytes
Uuid::from_slice(bytes).map_err(Into::into)
} else {
let text = std::str::from_utf8(bytes)?;

// parse a UUID from the text
Uuid::parse_str(text).map_err(Into::into)
}
}
}

Expand Down

0 comments on commit 2f875ab

Please sign in to comment.