22using Plugin ;
33using System ;
44using System . Collections . Generic ;
5+ using System . Linq ;
56using static Microsoft . CodeAnalysis . CSharp . SyntaxFactory ;
67using static System . String ;
78
@@ -15,6 +16,8 @@ public abstract class DbDriver(DotnetFramework dotnetFramework)
1516
1617 private HashSet < string > CsharpPrimitives { get ; } = [ "long" , "double" , "int" , "float" , "bool" , "DateTime" ] ;
1718
19+ protected abstract List < ColumnMapping > ColumnMappings { get ; }
20+
1821 public virtual UsingDirectiveSyntax [ ] GetUsingDirectives ( )
1922 {
2023 return
@@ -25,8 +28,6 @@ public virtual UsingDirectiveSyntax[] GetUsingDirectives()
2528 ] ;
2629 }
2730
28- protected abstract List < ( string , Func < int , string > , HashSet < string > ) > GetColumnMapping ( ) ;
29-
3031 public string AddNullableSuffix ( string csharpType , bool notNull )
3132 {
3233 if ( notNull ) return csharpType ;
@@ -42,10 +43,10 @@ public string GetColumnType(Column column)
4243 string GetTypeWithoutNullableSuffix ( )
4344 {
4445 var columnType = column . Type . Name . ToLower ( ) ;
45- foreach ( var ( csharpType , _, dbTypes ) in GetColumnMapping ( ) )
46+ foreach ( var columnMapping in ColumnMappings
47+ . Where ( columnMapping => columnMapping . DbTypes . ContainsKey ( columnType ) ) )
4648 {
47- if ( dbTypes . Contains ( columnType ) )
48- return csharpType ;
49+ return columnMapping . CsharpType ;
4950 }
5051 throw new NotSupportedException ( $ "Unsupported column type: { column . Type . Name } ") ;
5152 }
@@ -54,11 +55,23 @@ string GetTypeWithoutNullableSuffix()
5455 public string GetColumnReader ( Column column , int ordinal )
5556 {
5657 var columnType = column . Type . Name . ToLower ( ) ;
57- foreach ( var ( _, getDataReader , dbTypes ) in GetColumnMapping ( ) )
58+ foreach ( var columnMapping in ColumnMappings
59+ . Where ( columnMapping => columnMapping . DbTypes . ContainsKey ( columnType ) ) )
60+ {
61+ return columnMapping . ReaderFn ( ordinal ) ;
62+ }
63+ throw new NotSupportedException ( $ "Unsupported column type: { column . Type . Name } ") ;
64+ }
65+
66+ public string ? GetColumnDbTypeOverride ( Column column )
67+ {
68+ var columnType = column . Type . Name . ToLower ( ) ;
69+ foreach ( var columnMapping in ColumnMappings )
5870 {
59- if ( dbTypes . Contains ( columnType ) )
60- return getDataReader ( ordinal ) ;
71+ if ( columnMapping . DbTypes . TryGetValue ( columnType , out var dbTypeOverride ) )
72+ return dbTypeOverride ;
6173 }
74+
6275 throw new NotSupportedException ( $ "Unsupported column type: { column . Type . Name } ") ;
6376 }
6477
0 commit comments