@@ -55,6 +55,7 @@ pub struct EntityWriterContext {
5555 pub ( crate ) lib : bool ,
5656 pub ( crate ) serde_skip_hidden_column : bool ,
5757 pub ( crate ) serde_skip_deserializing_primary_key : bool ,
58+ pub ( crate ) use_new_dir_structure : bool ,
5859 pub ( crate ) model_extra_derives : TokenStream ,
5960 pub ( crate ) model_extra_attributes : TokenStream ,
6061 pub ( crate ) enum_extra_derives : TokenStream ,
@@ -172,6 +173,7 @@ impl EntityWriterContext {
172173 date_time_crate : DateTimeCrate ,
173174 schema_name : Option < String > ,
174175 lib : bool ,
176+ use_new_dir_structure : bool ,
175177 serde_skip_deserializing_primary_key : bool ,
176178 serde_skip_hidden_column : bool ,
177179 model_extra_derives : Vec < String > ,
@@ -191,6 +193,7 @@ impl EntityWriterContext {
191193 date_time_crate,
192194 schema_name,
193195 lib,
196+ use_new_dir_structure,
194197 serde_skip_deserializing_primary_key,
195198 serde_skip_hidden_column,
196199 model_extra_derives : bonus_derive ( model_extra_derives) ,
@@ -209,9 +212,18 @@ impl EntityWriter {
209212 let mut files = Vec :: new ( ) ;
210213 files. extend ( self . write_entities ( context) ) ;
211214 let with_prelude = context. with_prelude != WithPrelude :: None ;
212- files. push ( self . write_index_file ( context. lib , with_prelude, context. seaography ) ) ;
215+ files. push ( self . write_index_file (
216+ context. lib ,
217+ with_prelude,
218+ context. seaography ,
219+ context. use_new_dir_structure ,
220+ ) ) ;
213221 if with_prelude {
214- files. push ( self . write_prelude ( context. with_prelude , context. frontend_format ) ) ;
222+ files. push ( self . write_prelude (
223+ context. with_prelude ,
224+ context. frontend_format ,
225+ context. use_new_dir_structure ,
226+ ) ) ;
215227 }
216228 if !self . enums . is_empty ( ) {
217229 files. push ( self . write_sea_orm_active_enums (
@@ -229,7 +241,10 @@ impl EntityWriter {
229241 self . entities
230242 . iter ( )
231243 . map ( |entity| {
232- let entity_file = format ! ( "{}.rs" , entity. get_table_name_snake_case( ) ) ;
244+ let entity_file = match context. use_new_dir_structure {
245+ false => format ! ( "{}.rs" , entity. get_table_name_snake_case( ) ) ,
246+ true => format ! ( "entities/{}.rs" , entity. get_table_name_snake_case( ) ) ,
247+ } ;
233248 let column_info = entity
234249 . columns
235250 . iter ( )
@@ -304,7 +319,13 @@ impl EntityWriter {
304319 . collect ( )
305320 }
306321
307- pub fn write_index_file ( & self , lib : bool , prelude : bool , seaography : bool ) -> OutputFile {
322+ pub fn write_index_file (
323+ & self ,
324+ lib : bool ,
325+ prelude : bool ,
326+ seaography : bool ,
327+ use_new_dir_structure : bool ,
328+ ) -> OutputFile {
308329 let mut lines = Vec :: new ( ) ;
309330 Self :: write_doc_comment ( & mut lines) ;
310331 let code_blocks: Vec < TokenStream > = self . entities . iter ( ) . map ( Self :: gen_mod) . collect ( ) ;
@@ -335,7 +356,10 @@ impl EntityWriter {
335356
336357 let file_name = match lib {
337358 true => "lib.rs" . to_owned ( ) ,
338- false => "mod.rs" . to_owned ( ) ,
359+ false => match use_new_dir_structure {
360+ true => "entities.rs" . to_owned ( ) ,
361+ false => "mod.rs" . to_owned ( ) ,
362+ } ,
339363 } ;
340364
341365 OutputFile {
@@ -344,7 +368,12 @@ impl EntityWriter {
344368 }
345369 }
346370
347- pub fn write_prelude ( & self , with_prelude : WithPrelude , frontend_format : bool ) -> OutputFile {
371+ pub fn write_prelude (
372+ & self ,
373+ with_prelude : WithPrelude ,
374+ frontend_format : bool ,
375+ use_new_dir_structure : bool ,
376+ ) -> OutputFile {
348377 let mut lines = Vec :: new ( ) ;
349378 Self :: write_doc_comment ( & mut lines) ;
350379 if with_prelude == WithPrelude :: AllAllowUnusedImports {
@@ -362,8 +391,12 @@ impl EntityWriter {
362391 } )
363392 . collect ( ) ;
364393 Self :: write ( & mut lines, code_blocks) ;
394+ let file_name = match use_new_dir_structure {
395+ true => "entities/prelude.rs" . to_owned ( ) ,
396+ false => "prelude.rs" . to_owned ( ) ,
397+ } ;
365398 OutputFile {
366- name : "prelude.rs" . to_owned ( ) ,
399+ name : file_name ,
367400 content : lines. join ( "\n " ) ,
368401 }
369402 }
0 commit comments