@@ -70,6 +70,7 @@ pub fn output_schema(
7070 tables : table_data,
7171 fk_constraints : foreign_keys,
7272 include_docs : config. with_docs ,
73+ import_types : config. import_types ( ) ,
7374 } ;
7475
7576 if let Some ( schema_name) = config. schema_name ( ) {
@@ -96,7 +97,7 @@ pub fn output_schema(
9697 Ok ( ( ) )
9798}
9899
99- struct ModuleDefinition < ' a > ( & ' a str , TableDefinitions ) ;
100+ struct ModuleDefinition < ' a > ( & ' a str , TableDefinitions < ' a > ) ;
100101
101102impl < ' a > Display for ModuleDefinition < ' a > {
102103 fn fmt ( & self , f : & mut Formatter ) -> fmt:: Result {
@@ -110,13 +111,14 @@ impl<'a> Display for ModuleDefinition<'a> {
110111 }
111112}
112113
113- struct TableDefinitions {
114+ struct TableDefinitions < ' a > {
114115 tables : Vec < TableData > ,
115116 fk_constraints : Vec < ForeignKeyConstraint > ,
116117 include_docs : bool ,
118+ import_types : Option < & ' a [ String ] > ,
117119}
118120
119- impl Display for TableDefinitions {
121+ impl < ' a > Display for TableDefinitions < ' a > {
120122 fn fmt ( & self , f : & mut Formatter ) -> fmt:: Result {
121123 let mut is_first = true ;
122124 for table in & self . tables {
@@ -131,6 +133,7 @@ impl Display for TableDefinitions {
131133 TableDefinition {
132134 table,
133135 include_docs: self . include_docs,
136+ import_types: self . import_types,
134137 }
135138 ) ?;
136139 }
@@ -161,6 +164,7 @@ impl Display for TableDefinitions {
161164
162165struct TableDefinition < ' a > {
163166 table : & ' a TableData ,
167+ import_types : Option < & ' a [ String ] > ,
164168 include_docs : bool ,
165169}
166170
@@ -171,6 +175,13 @@ impl<'a> Display for TableDefinition<'a> {
171175 let mut out = PadAdapter :: new ( f) ;
172176 write ! ( out, "\n " ) ?;
173177
178+ if let Some ( types) = self . import_types {
179+ for import in types {
180+ writeln ! ( out, "use {};" , import) ?;
181+ }
182+ write ! ( out, "\n " ) ?;
183+ }
184+
174185 if self . include_docs {
175186 for d in self . table . docs . lines ( ) {
176187 writeln ! ( out, "///{}{}" , if d. is_empty( ) { "" } else { " " } , d) ?;
0 commit comments