This repository was archived by the owner on Dec 24, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +52
-0
lines changed
tests/ServiceStack.OrmLite.Tests Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Original file line number Diff line number Diff line change 11using System ;
2+ using ServiceStack . Text ;
23
34namespace ServiceStack . OrmLite
45{
@@ -30,6 +31,55 @@ public class ColumnSchema
3031 public object DefaultValue { get ; set ; }
3132 public string DataTypeName { get ; set ; }
3233 public string CollationType { get ; set ; }
34+
35+ public override string ToString ( )
36+ {
37+ var sql = StringBuilderCache . Allocate ( ) ;
38+
39+ sql . Append ( $ "{ ColumnName . PadRight ( 18 , ' ' ) } { DataTypeName } ") ;
40+ if ( NumericPrecision > 0 || NumericScale > 0 )
41+ {
42+ sql . Append ( "(" ) ;
43+ sql . Append ( NumericPrecision ) ;
44+ if ( NumericScale > 0 )
45+ {
46+ sql . Append ( "," ) ;
47+ sql . Append ( NumericScale ) ;
48+ }
49+ sql . Append ( ")" ) ;
50+ }
51+ else if ( ColumnSize > 0 )
52+ {
53+ sql . Append ( "(" ) ;
54+ sql . Append ( ColumnSize ) ;
55+ sql . Append ( ")" ) ;
56+ }
57+
58+ if ( IsKey )
59+ {
60+ sql . Append ( " PRIMARY KEY" ) ;
61+ if ( IsAutoIncrement )
62+ {
63+ sql . Append ( " " ) . Append ( "AUTOINCREMENT" ) ;
64+ }
65+ }
66+ else
67+ {
68+ sql . Append ( AllowDBNull ? " NULL" : " NOT NULL" ) ;
69+ }
70+
71+ if ( IsUnique )
72+ {
73+ sql . Append ( " UNIQUE" ) ;
74+ }
75+
76+ if ( DefaultValue != null )
77+ {
78+ sql . AppendFormat ( " DEFAULT ({0})" , DefaultValue ) ;
79+ }
80+
81+ return StringBuilderCache . ReturnAndFree ( sql ) ;
82+ }
3383 }
3484
3585}
Original file line number Diff line number Diff line change @@ -149,6 +149,8 @@ public void Can_get_Schema_Table()
149149
150150 var columnSchemas = db . GetTableColumns < Person > ( ) ;
151151
152+ columnSchemas . Each ( x => x . ToString ( ) . Print ( ) ) ;
153+
152154 columnSchemas . Each ( x => x . PrintDump ( ) ) ;
153155 }
154156 }
You can’t perform that action at this time.
0 commit comments