Skip to content

Commit

Permalink
rename attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
seanaye committed Jan 10, 2025
1 parent 5c5fd3f commit 39e8be3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
10 changes: 5 additions & 5 deletions sqlx-macros-core/src/derives/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ pub struct SqlxContainerAttributes {
}

pub enum JsonAttribute {
Mandatory,
Optional
NonNullable,
Nullable
}

pub struct SqlxChildAttributes {
Expand Down Expand Up @@ -170,10 +170,10 @@ pub fn parse_child_attributes(input: &[Attribute]) -> syn::Result<SqlxChildAttri
if meta.input.peek(syn::token::Paren) {
let content;
parenthesized!(content in meta.input);
let literal: Token![optional] = content.parse()?;
json = Some(JsonAttribute::Optional);
let literal: Token![nullable] = content.parse()?;
json = Some(JsonAttribute::Nullable);
} else {
json = Some(JsonAttribute::Mandatory);
json = Some(JsonAttribute::NonNullable);
}
}

Expand Down
14 changes: 7 additions & 7 deletions sqlx-macros-core/src/derives/row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ fn expand_derive_from_row_struct(
)
}
// Try from + Json mandatory
(false, Some(try_from), Some(JsonAttribute::Mandatory)) => {
(false, Some(try_from), Some(JsonAttribute::NonNullable)) => {
predicates
.push(parse_quote!(::sqlx::types::Json<#try_from>: ::sqlx::decode::Decode<#lifetime, R::Database>));
predicates.push(parse_quote!(::sqlx::types::Json<#try_from>: ::sqlx::types::Type<R::Database>));
Expand All @@ -175,24 +175,24 @@ fn expand_derive_from_row_struct(
})
)
},
// Try from + Json optional
(false, Some(try_from), Some(JsonAttribute::Optional)) => {
panic!("Cannot use both try from and json optional")
// Try from + Json nullable
(false, Some(try_from), Some(JsonAttribute::Nullable)) => {
panic!("Cannot use both try from and json nullable")
},
// Json
(false, None, Some(JsonAttribute::Mandatory)) => {
(false, None, Some(JsonAttribute::NonNullable)) => {
predicates
.push(parse_quote!(::sqlx::types::Json<#ty>: ::sqlx::decode::Decode<#lifetime, R::Database>));
predicates.push(parse_quote!(::sqlx::types::Json<#ty>: ::sqlx::types::Type<R::Database>));

parse_quote!(__row.try_get::<::sqlx::types::Json<_>, _>(#id_s).map(|x| x.0))
},
(false, None, Some(JsonAttribute::Optional)) => {
(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<R::Database>));

parse_quote!(__row.try_get::<::core::Option<::sqlx::types::Json<_>>, _>(#id_s).map(|x| x.map(|y| y.0)))
parse_quote!(__row.try_get::<::core::Option<::sqlx::types::Json<_>>, _>(#id_s).map(|x| x.flatten().map(|y| y.0)))
},
};

Expand Down

0 comments on commit 39e8be3

Please sign in to comment.