@@ -171,7 +171,7 @@ impl EntityWriter {
171171 pub fn generate ( self , context : & EntityWriterContext ) -> WriterOutput {
172172 let mut files = Vec :: new ( ) ;
173173 files. extend ( self . write_entities ( context) ) ;
174- files. push ( self . write_index_file ( context. lib ) ) ;
174+ files. push ( self . write_index_file ( context. lib , context . seaography ) ) ;
175175 files. push ( self . write_prelude ( ) ) ;
176176 if !self . enums . is_empty ( ) {
177177 files. push ( self . write_sea_orm_active_enums (
@@ -245,7 +245,7 @@ impl EntityWriter {
245245 . collect ( )
246246 }
247247
248- pub fn write_index_file ( & self , lib : bool ) -> OutputFile {
248+ pub fn write_index_file ( & self , lib : bool , seaography : bool ) -> OutputFile {
249249 let mut lines = Vec :: new ( ) ;
250250 Self :: write_doc_comment ( & mut lines) ;
251251 let code_blocks: Vec < TokenStream > = self . entities . iter ( ) . map ( Self :: gen_mod) . collect ( ) ;
@@ -266,6 +266,12 @@ impl EntityWriter {
266266 ) ;
267267 }
268268
269+ if seaography {
270+ lines. push ( "" . to_owned ( ) ) ;
271+ let ts = Self :: gen_seaography_entity_mod ( & self . entities , & self . enums ) ;
272+ Self :: write ( & mut lines, vec ! [ ts] ) ;
273+ }
274+
269275 let file_name = match lib {
270276 true => "lib.rs" . to_owned ( ) ,
271277 false => "mod.rs" . to_owned ( ) ,
@@ -704,6 +710,48 @@ impl EntityWriter {
704710 }
705711 }
706712
713+ pub fn gen_seaography_entity_mod (
714+ entities : & [ Entity ] ,
715+ enums : & BTreeMap < String , ActiveEnum > ,
716+ ) -> TokenStream {
717+ let mut ts = TokenStream :: new ( ) ;
718+ for entity in entities {
719+ let table_name_snake_case_ident = format_ident ! (
720+ "{}" ,
721+ escape_rust_keyword( entity. get_table_name_snake_case_ident( ) )
722+ ) ;
723+ ts = quote ! {
724+ #ts
725+ #table_name_snake_case_ident,
726+ }
727+ }
728+ ts = quote ! {
729+ seaography:: register_entity_modules!( [
730+ #ts
731+ ] ) ;
732+ } ;
733+
734+ let mut enum_ts = TokenStream :: new ( ) ;
735+ for active_enum in enums. values ( ) {
736+ let enum_name = & active_enum. enum_name . to_string ( ) ;
737+ let enum_iden = format_ident ! ( "{}" , enum_name. to_upper_camel_case( ) ) ;
738+ enum_ts = quote ! {
739+ #enum_ts
740+ sea_orm_active_enums:: #enum_iden
741+ }
742+ }
743+ if !enum_ts. is_empty ( ) {
744+ ts = quote ! {
745+ #ts
746+
747+ seaography:: register_active_enums!( [
748+ #enum_ts
749+ ] ) ;
750+ } ;
751+ }
752+ ts
753+ }
754+
707755 pub fn gen_prelude_use ( entity : & Entity ) -> TokenStream {
708756 let table_name_snake_case_ident = entity. get_table_name_snake_case_ident ( ) ;
709757 let table_name_camel_case_ident = entity. get_table_name_camel_case_ident ( ) ;
0 commit comments