Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions sea-orm-macros/src/derives/active_model_ex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ pub fn expand_derive_active_model_ex(
for field in fields.named.iter() {
if field.ident.is_some() && field_not_ignored_compound(field) {
let field_type = &field.ty;
let field_type = quote! { #field_type }
let field_type: String = quote! { #field_type }
.to_string() // e.g.: "Option < String >"
.replace(' ', ""); // Remove spaces
.split_whitespace()
.collect(); // Remove all whitespace

if is_compound_field(&field_type) {
let entity_path = extract_compound_entity(&field_type);
Expand All @@ -69,9 +70,10 @@ pub fn expand_derive_active_model_ex(
if let Some(ident) = &field.ident {
if field_not_ignored_compound(field) {
let field_type = &field.ty;
let field_type = quote! { #field_type }
let field_type: String = quote! { #field_type }
.to_string() // e.g.: "Option < String >"
.replace(' ', ""); // Remove spaces
.split_whitespace()
.collect(); // Remove all whitespace

let ty = if is_compound_field(&field_type) {
compound_fields.push(ident);
Expand Down Expand Up @@ -706,9 +708,10 @@ fn expand_active_model_setters(data: &Data) -> syn::Result<TokenStream> {
for field in &fields.named {
if let Some(ident) = &field.ident {
let field_type = &field.ty;
let field_type_str = quote! { #field_type }
let field_type_str: String = quote! { #field_type }
.to_string() // e.g.: "Option < String >"
.replace(' ', ""); // Remove spaces
.split_whitespace()
.collect(); // Remove all whitespace

let mut ignore = false;

Expand Down
10 changes: 8 additions & 2 deletions sea-orm-macros/src/derives/arrow_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ pub fn expand_derive_arrow_schema(
let field_type = &field.ty;

// Detect if field is Option<T> for nullability
let type_string = quote! { #field_type }.to_string().replace(' ', "");
let type_string: String = quote! { #field_type }
.to_string()
.split_whitespace()
.collect();
let is_nullable = type_string.starts_with("Option<");

// Parse field attributes
Expand Down Expand Up @@ -282,7 +285,10 @@ fn column_type_to_arrow_datatype(col_type: &str, arrow_attrs: &ArrowFieldAttrs)

/// Map Rust type to Arrow DataType (when no column_type specified)
fn rust_type_to_arrow_datatype(field_type: &Type, arrow_attrs: &ArrowFieldAttrs) -> TokenStream {
let type_string = quote! { #field_type }.to_string().replace(' ', "");
let type_string: String = quote! { #field_type }
.to_string()
.split_whitespace()
.collect();

// Strip Option<> wrapper if present
let inner_type = if type_string.starts_with("Option<") {
Expand Down
5 changes: 3 additions & 2 deletions sea-orm-macros/src/derives/entity_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,10 @@ pub fn expand_derive_entity_model(
};

let field_type = &field.ty;
let field_type = quote! { #field_type }
let field_type: String = quote! { #field_type }
.to_string() // e.g.: "Option < String >"
.replace(' ', ""); // Remove spaces
.split_whitespace()
.collect(); // Remove all whitespace

if ignore {
continue;
Expand Down
10 changes: 6 additions & 4 deletions sea-orm-macros/src/derives/model_ex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,10 @@ pub fn expand_sea_orm_model(input: ItemStruct, compact: bool) -> syn::Result<Tok

for field in all_fields.iter_mut() {
let field_type = &field.ty;
let field_type = quote! { #field_type }
let field_type: String = quote! { #field_type }
.to_string() // e.g.: "Option < String >"
.replace(' ', ""); // Remove spaces
.split_whitespace()
.collect(); // Remove all whitespace

if is_compound_field(&field_type) {
let entity_path = extract_compound_entity(&field_type);
Expand Down Expand Up @@ -173,9 +174,10 @@ pub fn expand_derive_model_ex(
for field in &fields.named {
if let Some(ident) = &field.ident {
let field_type = &field.ty;
let field_type = quote! { #field_type }
let field_type: String = quote! { #field_type }
.to_string() // e.g.: "Option < String >"
.replace(' ', ""); // Remove spaces
.split_whitespace()
.collect(); // Remove all whitespace

if is_compound_field(&field_type) {
let compound_attrs =
Expand Down
5 changes: 3 additions & 2 deletions sea-orm-macros/src/derives/typed_column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ pub fn expand_typed_column(
Ident::new(&field_name.to_upper_camel_case(), ident.span());

let field_type = &field.ty;
let field_type = quote! { #field_type }
let field_type: String = quote! { #field_type }
.to_string() // e.g.: "Option < String >"
.replace(' ', ""); // Remove spaces
.split_whitespace()
.collect(); // Remove all whitespace

let mut ignore = false;
let mut column_type = None;
Expand Down
5 changes: 3 additions & 2 deletions sea-orm-macros/src/derives/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ use syn::{Field, Ident, Meta, MetaNameValue, punctuated::Punctuated, token::Comm
/// Remove ignored fields and compound fields
pub(crate) fn field_not_ignored(field: &Field) -> bool {
let field_type = &field.ty;
let field_type = quote::quote! { #field_type }
let field_type: String = quote::quote! { #field_type }
.to_string() // e.g.: "Option < String >"
.replace(' ', ""); // Remove spaces
.split_whitespace()
.collect(); // Remove all whitespace

if is_compound_field(&field_type) {
return false;
Expand Down
5 changes: 3 additions & 2 deletions sea-orm-macros/src/derives/value_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,10 @@ impl DeriveValueTypeStruct {

let field_span = field.span();
let ty = field.ty;
let field_type = quote! { #ty }
let field_type: String = quote! { #ty }
.to_string() //E.g.: "Option < String >"
.replace(' ', ""); // Remove spaces
.split_whitespace()
.collect(); // Remove all whitespace
let field_type = if field_type.starts_with("Option<") {
&field_type[7..(field_type.len() - 1)] // Extract `T` out of `Option<T>`
} else {
Expand Down
Loading