diff --git a/sqlx-macros-core/src/derives/row.rs b/sqlx-macros-core/src/derives/row.rs index 83c4659c19..604986f90b 100644 --- a/sqlx-macros-core/src/derives/row.rs +++ b/sqlx-macros-core/src/derives/row.rs @@ -189,10 +189,10 @@ fn expand_derive_from_row_struct( }, (false, None, Some(JsonAttribute::Nullable)) => { predicates - .push(parse_quote!(::core::Option<::sqlx::types::Json<#ty>>: ::sqlx::decode::Decode<#lifetime, R::Database>)); - predicates.push(parse_quote!(::core::Option<::sqlx::types::Json<#ty>>: ::sqlx::types::Type)); + .push(parse_quote!(::core::option::Option<::sqlx::types::Json<#ty>>: ::sqlx::decode::Decode<#lifetime, R::Database>)); + predicates.push(parse_quote!(::core::option::Option<::sqlx::types::Json<#ty>>: ::sqlx::types::Type)); - parse_quote!(__row.try_get::<::core::Option<::sqlx::types::Json<_>>, _>(#id_s).map(|x| x.flatten().map(|y| y.0))) + parse_quote!(__row.try_get::<::core::option::Option<::sqlx::types::Json<_>>, _>(#id_s).map(|x| x.and_then(|y| y.0))) }, }; diff --git a/tests/mysql/macros.rs b/tests/mysql/macros.rs index 4dbdf07841..9c524c2a46 100644 --- a/tests/mysql/macros.rs +++ b/tests/mysql/macros.rs @@ -510,11 +510,11 @@ async fn test_from_row_json_attr_nullable() -> anyhow::Result<()> { let mut conn = new::().await?; - let record = sqlx::query_as::<_, Record>("select null as j") + let record = sqlx::query_as::<_, Record>("select NULL as j") .fetch_one(&mut conn) .await?; - assert_eq!(record.j, None); + assert!(record.j.is_none()); Ok(()) }