@@ -21,16 +21,19 @@ public class ApplicationArguments
2121 public string Database { get ; set ; }
2222 public string Table { get ; set ; }
2323 public bool GenerateConstructorAndOutput { get ; set ; }
24+ public bool GenerateMarkupPages { get ; set ; }
2425 }
2526
2627 public class Column
2728 {
2829 public string Name { get ; set ; }
2930 public Type Type { get ; set ; }
31+ public string ColumnType { get ; set ; }
3032
3133 public Column ( MySqlDataReader reader )
3234 {
3335 this . Name = reader . GetString ( 1 ) ;
36+ this . ColumnType = reader . GetString ( 2 ) ;
3437 }
3538
3639 public override string ToString ( )
@@ -115,6 +118,41 @@ private static void DbToClasses(string dbName, Dictionary<string, List<Column>>
115118 }
116119 }
117120
121+ private static void DbToMarkupPage ( string dbName , Dictionary < string , List < Column > > db )
122+ {
123+ var wikiDir = $ "{ dbName } -wiki";
124+ var wikiTableDir = $ "{ wikiDir } /tables";
125+
126+ if ( ! Directory . Exists ( wikiDir ) )
127+ Directory . CreateDirectory ( wikiDir ) ;
128+ if ( ! Directory . Exists ( wikiTableDir ) )
129+ Directory . CreateDirectory ( wikiTableDir ) ;
130+
131+ var sb = new StringBuilder ( ) ;
132+ // generate index pages
133+ foreach ( var table in db )
134+ sb . AppendLine ( $ "* [[{ table . Key . FirstCharUpper ( ) } |{ table . Key . ToLower ( ) } ]]") ;
135+
136+ var sw = new StreamWriter ( $ "{ wikiDir } /{ dbName } .txt") ;
137+ sw . Write ( sb . ToString ( ) ) ;
138+ sw . Close ( ) ;
139+ sb . Clear ( ) ;
140+
141+ sb . AppendLine ( "Column | Type | Description" ) ;
142+ sb . AppendLine ( "--- | --- | ---" ) ;
143+
144+ foreach ( var table in db )
145+ {
146+ foreach ( var column in table . Value )
147+ sb . AppendLine ( $ "{ column . Name . FirstCharUpper ( ) } | { column . ColumnType } | ") ;
148+ sw = new StreamWriter ( $ "{ wikiTableDir } /{ table . Key } .txt") ;
149+ sw . Write ( sb . ToString ( ) ) ;
150+ sw . Close ( ) ;
151+ sb . Clear ( ) ;
152+ }
153+
154+ }
155+
118156 static void Main ( string [ ] args )
119157 {
120158 var parser = new FluentCommandLineParser < ApplicationArguments > ( ) ;
@@ -126,6 +164,9 @@ static void Main(string[] args)
126164 parser . Setup ( arg => arg . Table ) . As ( 't' , "table" ) . SetDefault ( String . Empty ) . WithDescription ( "(optional) Table name, will generate entire database if not specified" ) ;
127165 parser . Setup ( arg => arg . GenerateConstructorAndOutput ) . As ( 'g' , "generateconstructorandoutput" )
128166 . SetDefault ( false ) . WithDescription ( "(optional) Generate a reading constructor and SQL statement output - Activate with -g true" ) ;
167+ parser . Setup ( arg => arg . GenerateMarkupPages ) . As ( 'm' , "generatemarkuppages" )
168+ . SetDefault ( false )
169+ . WithDescription ( "(optional) Generate markup pages for database and tables which can be used in wikis" ) ;
129170 parser . SetupHelp ( "?" , "help" ) . Callback ( text => Console . WriteLine ( text ) ) ;
130171
131172 var result = parser . Parse ( args ) ;
@@ -151,7 +192,7 @@ static void Main(string[] args)
151192 using ( var cmd = con . CreateCommand ( ) )
152193 {
153194 cmd . CommandText =
154- $ "SELECT TABLE_NAME, COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '{ conf . Database } '";
195+ $ "SELECT TABLE_NAME, COLUMN_NAME, COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '{ conf . Database } '";
155196 if ( ! conf . Table . Equals ( string . Empty ) )
156197 cmd . CommandText += $ " AND TABLE_NAME = '{ conf . Table } '";
157198
@@ -183,6 +224,8 @@ static void Main(string[] args)
183224 }
184225
185226 DbToClasses ( conf . Database , database , conf . GenerateConstructorAndOutput ) ;
227+ if ( conf . GenerateMarkupPages )
228+ DbToMarkupPage ( conf . Database , database ) ;
186229 Console . WriteLine ( "Successfully generated C# classes!" ) ;
187230 }
188231 Console . ReadLine ( ) ;
0 commit comments