1+ namespace Simple . Data . Ado . Metadata
2+ {
3+ using System . Collections . Generic ;
4+ using System . Data ;
5+ using System . Linq ;
6+ using System . Threading . Tasks ;
7+ using Schema ;
8+
9+ public class AdoMetadata : IMetadata
10+ {
11+ private static readonly IList < Column > EmptyColumns = new Column [ 0 ] ;
12+ private readonly DatabaseSchema _schema ;
13+
14+ public AdoMetadata ( AdoAdapter adapter )
15+ {
16+ _schema = adapter . GetSchema ( ) ;
17+ }
18+
19+ public Task < IList < Table > > GetTables ( )
20+ {
21+ IList < Table > tables = _schema . Tables . Select ( t => new Table ( t . Schema , t . ActualName ) ) . ToList ( ) ;
22+ return Task . FromResult ( tables ) ;
23+ }
24+
25+ public Task < IList < Column > > GetColumns ( Table table )
26+ {
27+ IList < Column > columns ;
28+ var schemaTable = _schema . FindTable ( new ObjectName ( table . Schema , table . Name ) ) ;
29+ if ( schemaTable == null )
30+ {
31+ columns = EmptyColumns ;
32+ }
33+ else
34+ {
35+ columns = schemaTable . Columns . Select ( c => new Column ( c . ActualName , c . DbType , c . TypeName , c . IsIdentity , c . MaxLength ) ) . ToList ( ) ;
36+ }
37+ return Task . FromResult ( columns ) ;
38+ }
39+ }
40+
41+ public class Table
42+ {
43+ private readonly string _schema ;
44+ private readonly string _name ;
45+
46+ public Table ( string schema , string name )
47+ {
48+ _schema = schema ;
49+ _name = name ;
50+ }
51+
52+ public string Schema
53+ {
54+ get { return _schema ; }
55+ }
56+
57+ public string Name
58+ {
59+ get { return _name ; }
60+ }
61+ }
62+
63+ public class Column
64+ {
65+ private readonly string _name ;
66+ private readonly DbType _dbType ;
67+ private readonly string _typeName ;
68+ private readonly bool _isIdentity ;
69+ private readonly int _maxLength ;
70+
71+ public Column ( string name , DbType dbType , string typeName , bool isIdentity , int maxLength )
72+ {
73+ _name = name ;
74+ _dbType = dbType ;
75+ _typeName = typeName ;
76+ _isIdentity = isIdentity ;
77+ _maxLength = maxLength ;
78+ }
79+
80+ public int MaxLength
81+ {
82+ get { return _maxLength ; }
83+ }
84+
85+ public bool IsIdentity
86+ {
87+ get { return _isIdentity ; }
88+ }
89+
90+ public string TypeName
91+ {
92+ get { return _typeName ; }
93+ }
94+
95+ public DbType DbType
96+ {
97+ get { return _dbType ; }
98+ }
99+
100+ public string Name
101+ {
102+ get { return _name ; }
103+ }
104+ }
105+ }
0 commit comments