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 1
1
using System ;
2
+ using ServiceStack . Text ;
2
3
3
4
namespace ServiceStack . OrmLite
4
5
{
@@ -30,6 +31,55 @@ public class ColumnSchema
30
31
public object DefaultValue { get ; set ; }
31
32
public string DataTypeName { get ; set ; }
32
33
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
+ }
33
83
}
34
84
35
85
}
Original file line number Diff line number Diff line change @@ -149,6 +149,8 @@ public void Can_get_Schema_Table()
149
149
150
150
var columnSchemas = db . GetTableColumns < Person > ( ) ;
151
151
152
+ columnSchemas . Each ( x => x . ToString ( ) . Print ( ) ) ;
153
+
152
154
columnSchemas . Each ( x => x . PrintDump ( ) ) ;
153
155
}
154
156
}
You can’t perform that action at this time.
0 commit comments