11//! Module for parsing sql and comments and returning `table` and `column`
22//! information, including comments
3+ use core:: fmt;
4+
35use sqlparser:: ast:: { Ident , ObjectName , ObjectNamePart , Spanned , Statement } ;
46
57use crate :: { ast:: ParsedSqlFile , comments:: Comments , error:: DocError } ;
@@ -32,8 +34,20 @@ impl ColumnDoc {
3234 /// Getter for the field `doc`
3335 #[ must_use]
3436 #[ allow( clippy:: missing_const_for_fn) ]
35- pub fn doc ( & self ) -> & Option < String > {
36- & self . doc
37+ pub fn doc ( & self ) -> Option < & str > {
38+ self . doc . as_deref ( )
39+ }
40+ }
41+
42+ impl fmt:: Display for ColumnDoc {
43+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
44+ writeln ! ( f, "Column Name: {}" , self . name( ) ) ?;
45+ if let Some ( c) = self . doc ( ) {
46+ writeln ! ( f, "Column Doc: {c}" ) ?;
47+ } else {
48+ writeln ! ( f, "No Column Doc Found" ) ?;
49+ }
50+ Ok ( ( ) )
3751 }
3852}
3953
@@ -66,6 +80,12 @@ impl TableDoc {
6680 Self { schema, name, doc, columns }
6781 }
6882
83+ /// Getter for the `Schema` of the table (if there is one)
84+ #[ must_use]
85+ pub fn schema ( & self ) -> Option < & str > {
86+ self . schema . as_deref ( )
87+ }
88+
6989 /// Getter for the `name` field
7090 #[ must_use]
7191 #[ allow( clippy:: missing_const_for_fn) ]
@@ -76,8 +96,8 @@ impl TableDoc {
7696 /// Getter for the `doc` field
7797 #[ must_use]
7898 #[ allow( clippy:: missing_const_for_fn) ]
79- pub fn doc ( & self ) -> & Option < String > {
80- & self . doc
99+ pub fn doc ( & self ) -> Option < & str > {
100+ self . doc . as_deref ( )
81101 }
82102
83103 /// Getter for the `columns` field
@@ -88,6 +108,30 @@ impl TableDoc {
88108 }
89109}
90110
111+ impl fmt:: Display for TableDoc {
112+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
113+ if let Some ( s) = self . schema ( ) {
114+ writeln ! ( f, "Table Schema: {s}" ) ?;
115+ } else {
116+ writeln ! ( f, "No Table Schema" ) ?;
117+ }
118+
119+ writeln ! ( f, "Table Name: {}" , self . name( ) ) ?;
120+
121+ if let Some ( d) = self . doc ( ) {
122+ writeln ! ( f, "Table Doc: {d}" ) ?;
123+ } else {
124+ writeln ! ( f, "No Table Doc" ) ?;
125+ }
126+
127+ writeln ! ( f, "Table Column Docs: " ) ?;
128+ for col in self . columns ( ) {
129+ writeln ! ( f, " {col}" ) ?;
130+ }
131+ Ok ( ( ) )
132+ }
133+ }
134+
91135/// Structure for containing the docs for every `Table` in an `.sql` file as a
92136/// `Vec` of [`TableDoc`]
93137#[ derive( Clone , Debug , Eq , PartialEq ) ]
0 commit comments