diff --git a/src/query/json.rs b/src/query/json.rs index da91fb3b6..6b5fad36c 100644 --- a/src/query/json.rs +++ b/src/query/json.rs @@ -34,6 +34,13 @@ impl FromQueryResult for JsonValue { } }; } + macro_rules! match_mysql_compatible_type { + ( $type: ty ) => { + if <$type as Type>::compatible(col_type) { + try_get_type!($type, col) + } + }; + } match_mysql_type!(bool); match_mysql_type!(i8); match_mysql_type!(i16); @@ -64,9 +71,9 @@ impl FromQueryResult for JsonValue { match_mysql_type!(time::OffsetDateTime); #[cfg(feature = "with-rust_decimal")] match_mysql_type!(rust_decimal::Decimal); + match_mysql_compatible_type!(String); #[cfg(feature = "with-json")] try_get_type!(serde_json::Value, col); - try_get_type!(String, col); #[cfg(feature = "with-uuid")] try_get_type!(uuid::Uuid, col); try_get_type!(Vec, col); diff --git a/tests/uuid_tests.rs b/tests/uuid_tests.rs index 4c7f6a380..fddd1338f 100644 --- a/tests/uuid_tests.rs +++ b/tests/uuid_tests.rs @@ -39,33 +39,18 @@ pub async fn insert_metadata(db: &DatabaseConnection) -> Result<(), DbErr> { .one(db) .await?; - if cfg!(feature = "sqlx-mysql") { - assert_eq!( - json, - Some(json!({ - "uuid": metadata.uuid, - "type": metadata.ty, - "key": metadata.key, - "value": 1.18, - "bytes": "\u{1}\u{2}\u{3}", - "date": metadata.date, - "time": metadata.time, - })) - ); - } else { - assert_eq!( - json, - Some(json!({ - "uuid": metadata.uuid, - "type": metadata.ty, - "key": metadata.key, - "value": metadata.value, - "bytes": metadata.bytes, - "date": metadata.date, - "time": metadata.time, - })) - ); - } + assert_eq!( + json, + Some(json!({ + "uuid": metadata.uuid, + "type": metadata.ty, + "key": metadata.key, + "value": metadata.value, + "bytes": metadata.bytes, + "date": metadata.date, + "time": metadata.time, + })) + ); Ok(()) }