@@ -21,16 +21,19 @@ public class ApplicationArguments
21
21
public string Database { get ; set ; }
22
22
public string Table { get ; set ; }
23
23
public bool GenerateConstructorAndOutput { get ; set ; }
24
+ public bool GenerateMarkupPages { get ; set ; }
24
25
}
25
26
26
27
public class Column
27
28
{
28
29
public string Name { get ; set ; }
29
30
public Type Type { get ; set ; }
31
+ public string ColumnType { get ; set ; }
30
32
31
33
public Column ( MySqlDataReader reader )
32
34
{
33
35
this . Name = reader . GetString ( 1 ) ;
36
+ this . ColumnType = reader . GetString ( 2 ) ;
34
37
}
35
38
36
39
public override string ToString ( )
@@ -115,6 +118,41 @@ private static void DbToClasses(string dbName, Dictionary<string, List<Column>>
115
118
}
116
119
}
117
120
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
+
118
156
static void Main ( string [ ] args )
119
157
{
120
158
var parser = new FluentCommandLineParser < ApplicationArguments > ( ) ;
@@ -126,6 +164,9 @@ static void Main(string[] args)
126
164
parser . Setup ( arg => arg . Table ) . As ( 't' , "table" ) . SetDefault ( String . Empty ) . WithDescription ( "(optional) Table name, will generate entire database if not specified" ) ;
127
165
parser . Setup ( arg => arg . GenerateConstructorAndOutput ) . As ( 'g' , "generateconstructorandoutput" )
128
166
. 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" ) ;
129
170
parser . SetupHelp ( "?" , "help" ) . Callback ( text => Console . WriteLine ( text ) ) ;
130
171
131
172
var result = parser . Parse ( args ) ;
@@ -151,7 +192,7 @@ static void Main(string[] args)
151
192
using ( var cmd = con . CreateCommand ( ) )
152
193
{
153
194
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 } '";
155
196
if ( ! conf . Table . Equals ( string . Empty ) )
156
197
cmd . CommandText += $ " AND TABLE_NAME = '{ conf . Table } '";
157
198
@@ -183,6 +224,8 @@ static void Main(string[] args)
183
224
}
184
225
185
226
DbToClasses ( conf . Database , database , conf . GenerateConstructorAndOutput ) ;
227
+ if ( conf . GenerateMarkupPages )
228
+ DbToMarkupPage ( conf . Database , database ) ;
186
229
Console . WriteLine ( "Successfully generated C# classes!" ) ;
187
230
}
188
231
Console . ReadLine ( ) ;
0 commit comments