pub fn compile_generated_code(&self) -> String {
        let mut code = String::new();

        for (model, table) in self.database_tables() {
            let ident = format_ident!("{}", model.name);
            let db_module_ident = format_ident!("{}", table.name);

            let mut from_schema_fields = Vec::new();
            let mut from_db_fields = Vec::new();

            for field in &model.fields {
                let field_ident = format_ident!("{}", field.name);

                let ty = strip_ty_option(&field.ty);

                if is_ty_vec(ty) {
                    from_schema_fields.push(
                        quote!(#field_ident: val.#field_ident.into_iter().map(|v| v.into()).collect()),
                    );
                    from_db_fields.push(
                        quote!(#field_ident: val.#field_ident.into_iter().map(|v| v.into()).collect()),
                    );
                } else {
                    from_schema_fields.push(quote!(#field_ident: val.#field_ident.into()));
                    from_db_fields.push(quote!(#field_ident: val.#field_ident.into()));
                }
            }

            let expanded = quote!(
                impl ::std::convert::From<crate::#db_module_ident::Model> for ::schema::#ident {
                    #[allow(unused_variables)]
                    fn from(val: crate::#db_module_ident::Model) -> Self {
                        Self {
                            #( #from_schema_fields, )*
                        }
                    }
                }

                impl ::std::convert::From<::schema::#ident> for crate::#db_module_ident::Model {
                    #[allow(unused_variables)]
                    fn from(val: ::schema::#ident) -> Self {
                        Self {
                            #( #from_db_fields, )*
                        }
                    }
                }
            );

            write!(code, "{}", expanded.to_string()).unwrap();
        }

        for (model, table) in self.database_sub_tables() {
            let ident = format_ident!("{}", model.name);
            let db_module_ident = format_ident!("{}", table.name);

            let active_values = model.fields.iter().map(|field| {
                let field_ident = format_ident!("{}", field.name);
                
                let self_field = if is_ty_option(&field.ty) {
                    let db_field = table.columns.iter().find(|column| column.name == field.name).unwrap();
                    match &db_field.default {
                        Some(DatabaseDefault::Bool(b)) => quote!(self.#field_ident.unwrap_or(#b)),
                        Some(DatabaseDefault::Float(f)) => {
                            let f = Literal::i64_unsuffixed(*f);
                            quote!(self.#field_ident.unwrap_or(#f))
                        },
                        Some(DatabaseDefault::Int(i)) => {
                            let i = Literal::u64_unsuffixed(*i);
                            quote!(self.#field_ident.unwrap_or(#i))
                        },
                        Some(DatabaseDefault::String(s)) => quote!(self.#field_ident.unwrap_or(#s)),
                        _ => quote!(self.#field_ident),
                    }
                } else {
                    quote!(self.#field_ident)
                };

                quote!(
                    #field_ident: ::sea_orm::entity::IntoActiveValue::into_active_value(#self_field).into()
                )
            });
            
            let expanded = quote!(
                impl ::sea_orm::entity::IntoActiveModel<crate::#db_module_ident::ActiveModel> for ::schema::#ident {
                    fn into_active_model(self) -> crate::#db_module_ident::ActiveModel {
                        crate::#db_module_ident::ActiveModel {
                            #( #active_values, )*
                            ..Default::default()
                        }
                    }
                }
            );

            write!(code, "{}", expanded.to_string()).unwrap();
        }

        code.trim().to_string()
    }
/// Compiles generated Rust code from schemas and services.
Compiles generated Rust code from schemas and services.
Compiles generated Rust code from schemas and services .
pub fn compile_generated_code(&self) -> String {
        let mut code = String::new();
        for (model, table) in self.database_tables() {
            let ident = format_ident!("{}", model.name);
            let db_module_ident = format_ident!("{}", table.name);
            let mut from_schema_fields = Vec::new();
            let mut from_db_fields = Vec::new();
            for field in &model.fields {
                let field_ident = format_ident!("{}", field.name);
                let ty = strip_ty_option(&field.ty);
                if is_ty_vec(ty) {
                    from_schema_fields.push(
                        quote!(#field_ident: val.#field_ident.into_iter().map(|v| v.into()).collect()),
                    );
                    from_db_fields.push(
                        quote!(#field_ident: val.#field_ident.into_iter().map(|v| v.into()).collect()),
                    );
                } else {
                    from_schema_fields.push(quote!(#field_ident: val.#field_ident.into()));
                    from_db_fields.push(quote!(#field_ident: val.#field_ident.into()));
                }
            }
            let expanded = quote!(
                impl ::std::convert::From<crate::#db_module_ident::Model> for ::schema::#ident {
                    #[allow(unused_variables)]
                    fn from(val: crate::#db_module_ident::Model) -> Self {
                        Self {
                            #( #from_schema_fields, )*
                        }
                    }
                }
                impl ::std::convert::From<::schema::#ident> for crate::#db_module_ident::Model {
                    #[allow(unused_variables)]
                    fn from(val: ::schema::#ident) -> Self {
                        Self {
                            #( #from_db_fields, )*
                        }
                    }
                }
            );
            write!(code, "{}", expanded.to_string()).unwrap();
        }
        for (model, table) in self.database_sub_tables() {
            let ident = format_ident!("{}", model.name);
            let db_module_ident = format_ident!("{}", table.name);
            let active_values = model.fields.iter().map(|field| {
                let field_ident = format_ident!("{}", field.name);
                let self_field = if is_ty_option(&field.ty) {
                    let db_field = table.columns.iter().find(|column| column.name == field.name).unwrap();
                    match &db_field.default {
                        Some(DatabaseDefault::Bool(b)) => quote!(self.#field_ident.unwrap_or(#b)),
                        Some(DatabaseDefault::Float(f)) => {
                            let f = Literal::i64_unsuffixed(*f);
                            quote!(self.#field_ident.unwrap_or(#f))
                        },
                        Some(DatabaseDefault::Int(i)) => {
                            let i = Literal::u64_unsuffixed(*i);
                            quote!(self.#field_ident.unwrap_or(#i))
                        },
                        Some(DatabaseDefault::String(s)) => quote!(self.#field_ident.unwrap_or(#s)),
                        _ => quote!(self.#field_ident),
                    }
                } else {
                    quote!(self.#field_ident)
                };
                quote!(
                    #field_ident: ::sea_orm::entity::IntoActiveValue::into_active_value(#self_field).into()
                )
            });
            let expanded = quote!(
                impl ::sea_orm::entity::IntoActiveModel<crate::#db_module_ident::ActiveModel> for ::schema::#ident {
                    fn into_active_model(self) -> crate::#db_module_ident::ActiveModel {
                        crate::#db_module_ident::ActiveModel {
                            #( #active_values, )*
                            ..Default::default()
                        }
                    }
                }
            );
            write!(code, "{}", expanded.to_string()).unwrap();
        }
        code.trim().to_string()
    }
pub fn compile_generated_code ( & self ) -> String { let mut code = String :: new ( ) ; for ( model , table ) in self . database_tables ( ) { let ident = format_ident ! ( " " model name ) ; let db_module_ident = format_ident ! ( " " table name ) ; let mut from_schema_fields = Vec :: new ( ) ; let mut from_db_fields = Vec :: new ( ) ; for field in & model . fields { let field_ident = format_ident ! ( " " field name ) ; let ty = strip_ty_option ( & field . ty ) ; if is_ty_vec ( ty ) { from_schema_fields . push ( quote ! ( field_ident val field_ident into_iter ( ) map ( v v into ( ) ) collect ( ) ) , ) ; from_db_fields . push ( quote ! ( field_ident val field_ident into_iter ( ) map ( v v into ( ) ) collect ( ) ) , ) ; } else { from_schema_fields . push ( quote ! ( field_ident val field_ident into ( ) ) ) ; from_db_fields . push ( quote ! ( field_ident val field_ident into ( ) ) ) ; } } let expanded = quote ! ( impl std convert From crate db_module_ident Model for schema ident { [ allow ( unused_variables ) ] fn from ( val crate db_module_ident Model ) Self { Self { ( from_schema_fields ) } } } impl std convert From schema ident for crate db_module_ident Model { [ allow ( unused_variables ) ] fn from ( val schema ident ) Self { Self { ( from_db_fields ) } } } ) ; write ! ( code " " expanded to_string ( ) ) . unwrap ( ) ; } for ( model , table ) in self . database_sub_tables ( ) { let ident = format_ident ! ( " " model name ) ; let db_module_ident = format_ident ! ( " " table name ) ; let active_values = model . fields . iter ( ) . map ( | field | { let field_ident = format_ident ! ( " " field name ) ; let self_field = if is_ty_option ( & field . ty ) { let db_field = table . columns . iter ( ) . find ( | column | column . name == field . name ) . unwrap ( ) ; match & db_field . default { Some ( DatabaseDefault :: Bool ( b ) ) => quote ! ( self field_ident unwrap_or ( b ) ) , Some ( DatabaseDefault :: Float ( f ) ) => { let f = Literal :: i64_unsuffixed ( * f ) ; quote ! ( self field_ident unwrap_or ( f ) ) } , Some ( DatabaseDefault :: Int ( i ) ) => { let i = Literal :: u64_unsuffixed ( * i ) ; quote ! ( self field_ident unwrap_or ( i ) ) } , Some ( DatabaseDefault :: String ( s ) ) => quote ! ( self field_ident unwrap_or ( s ) ) , _ => quote ! ( self field_ident ) , } } else { quote ! ( self field_ident ) } ; quote ! ( field_ident sea_orm entity IntoActiveValue into_active_value ( self_field ) into ( ) ) } ) ; let expanded = quote ! ( impl sea_orm entity IntoActiveModel crate db_module_ident ActiveModel for schema ident { fn into_active_model ( self ) crate db_module_ident ActiveModel { crate db_module_ident ActiveModel { ( active_values ) Default default ( ) } } } ) ; write ! ( code " " expanded to_string ( ) ) . unwrap ( ) ; } code . trim ( ) . to_string ( ) }
Compiles generated Rust code from schemas and services.
Compiles generated Rust code from schemas and services .
&self
&self