@@ -25,6 +25,9 @@ pub struct Config{
2525
2626 /// base directory for the generated content
2727 pub base_dir : String ,
28+
29+ /// whether to include generating views
30+ pub include_views : bool ,
2831}
2932
3033impl Config {
@@ -36,6 +39,7 @@ impl Config{
3639 use_condensed_name : true ,
3740 generate_table_meta : true ,
3841 base_dir : "./src" . to_string ( ) ,
42+ include_views : true ,
3943 }
4044 }
4145
@@ -75,9 +79,9 @@ impl Config{
7579pub fn get_all_tables ( db_dev : & DatabaseDev ) ->Vec < Table > {
7680 let all_tables_names = db_dev. get_all_tables ( ) ;
7781 let mut all_table_def: Vec < Table > = Vec :: new ( ) ;
78- for ( schema, table) in all_tables_names{
82+ for ( schema, table, is_view ) in all_tables_names{
7983 println ! ( "Extracted {}.{}" , schema, table) ;
80- let meta = db_dev. get_table_metadata ( & schema, & table) ;
84+ let meta = db_dev. get_table_metadata ( & schema, & table, is_view ) ;
8185 all_table_def. push ( meta) ;
8286 }
8387 all_table_def
@@ -136,6 +140,7 @@ pub fn generate_tables(db_dev:&DatabaseDev, only_tables:Vec<String>, config:&Con
136140 generate_mod_rs ( & config, & tables) ;
137141 generate_mod_table_names ( & config, & tables) ;
138142 generate_mod_column_names ( & config, & tables) ;
143+ generate_mod_schema_names ( & config, & tables) ;
139144}
140145
141146/// the gernaration of tables should be placed on their respective directory
@@ -210,6 +215,19 @@ fn generate_mod_per_schema(config:&Config, all_tables:&Vec<Table>){
210215 }
211216}
212217
218+ /// listing down schemas in the database
219+ fn generate_mod_schema_names ( config : & Config , all_tables : & Vec < Table > ) {
220+ let schemas = get_schemas ( all_tables) ;
221+ let mut w = Writer :: new ( ) ;
222+ for schema in schemas{
223+ w. ln ( ) ;
224+ w. appendln ( "#[allow(non_upper_case_globals)]" ) ;
225+ w. appendln ( & format ! ( "pub const {}: &'static str = \" {}\" ;" , schema, schema) ) ;
226+ }
227+ let module_dir = config. module_base_dir ( ) ;
228+ let mod_file = format ! ( "{}/schema.rs" , module_dir) ;
229+ save_to_file ( & mod_file, & w. src ) ;
230+ }
213231/// listing of all table names in the system
214232fn generate_mod_table_names ( config : & Config , all_tables : & Vec < Table > ) {
215233 let mut unique_table = vec ! [ ] ;
@@ -261,8 +279,11 @@ fn generate_mod_rs(config:&Config, all_tables:&Vec<Table>){
261279 w. append ( schema) ;
262280 w. appendln ( ";" ) ;
263281 }
282+ w. ln ( ) ;
283+ w. appendln ( "pub mod schema;" ) ;
264284 w. appendln ( "pub mod table;" ) ;
265285 w. appendln ( "pub mod column;" ) ;
286+ w. ln ( ) ;
266287 w. appendln ( "use rustorm::table::Table;" ) ;
267288 w. appendln ( "use rustorm::table::IsTable;" ) ;
268289 for table in all_tables{
0 commit comments