File tree Expand file tree Collapse file tree 3 files changed +52
-0
lines changed Expand file tree Collapse file tree 3 files changed +52
-0
lines changed Original file line number Diff line number Diff line change @@ -46,7 +46,39 @@ class MongoConnector extends AdminForthBaseConnector implements IAdminForthDataS
46
46
[ AdminForthSortDirections . asc ] : 1 ,
47
47
[ AdminForthSortDirections . desc ] : - 1 ,
48
48
} ;
49
+ async getAllTables ( ) : Promise < Array < string > > {
50
+ const db = this . client . db ( ) ;
51
+
52
+ const collections = await db . listCollections ( ) . toArray ( ) ;
53
+
54
+ return collections . map ( col => col . name ) ;
55
+ }
49
56
57
+ async getAllColumnsInTable ( collectionName : string ) : Promise < Array < string > > {
58
+
59
+ const sampleDocs = await this . client . db ( ) . collection ( collectionName ) . find ( { } ) . limit ( 100 ) . toArray ( ) ;
60
+
61
+ const fieldSet = new Set < string > ( ) ;
62
+
63
+ function flattenObject ( obj : any , prefix = '' ) {
64
+ Object . entries ( obj ) . forEach ( ( [ key , value ] ) => {
65
+ const fullKey = prefix ? `${ prefix } .${ key } ` : key ;
66
+ if ( value && typeof value === 'object' && ! Array . isArray ( value ) && ! ( value instanceof Date ) ) {
67
+ flattenObject ( value , fullKey ) ;
68
+ } else {
69
+ fieldSet . add ( fullKey ) ;
70
+ }
71
+ } ) ;
72
+ }
73
+
74
+ for ( const doc of sampleDocs ) {
75
+ flattenObject ( doc ) ;
76
+ }
77
+
78
+ return Array . from ( fieldSet ) ;
79
+ }
80
+
81
+
50
82
async discoverFields ( resource ) {
51
83
return resource . columns . filter ( ( col ) => ! col . virtual ) . reduce ( ( acc , col ) => {
52
84
if ( ! col . type ) {
Original file line number Diff line number Diff line change @@ -45,6 +45,24 @@ class PostgresConnector extends AdminForthBaseConnector implements IAdminForthDa
45
45
[ AdminForthSortDirections . desc ] : 'DESC' ,
46
46
} ;
47
47
48
+ async getAllTables ( ) : Promise < Array < string > > {
49
+ const res = await this . client . query ( `
50
+ SELECT table_name
51
+ FROM information_schema.tables
52
+ WHERE table_schema = 'public' AND table_type = 'BASE TABLE';
53
+ ` ) ;
54
+ return res . rows . map ( row => row . table_name ) ;
55
+ }
56
+
57
+ async getAllColumnsInTable ( tableName : string ) : Promise < Array < string > > {
58
+ const res = await this . client . query ( `
59
+ SELECT column_name
60
+ FROM information_schema.columns
61
+ WHERE table_name = $1 AND table_schema = 'public';
62
+ ` , [ tableName ] ) ;
63
+ return res . rows . map ( row => row . column_name ) ;
64
+ }
65
+
48
66
async discoverFields ( resource ) {
49
67
50
68
const tableName = resource . table ;
Original file line number Diff line number Diff line change @@ -391,6 +391,7 @@ class AdminForth implements IAdminForth {
391
391
// console.log(`Connector ${dataSourceId} does not have getAllTables method`);
392
392
results [ dataSourceId ] = [ ] ;
393
393
}
394
+ await connector . close ( ) ;
394
395
} )
395
396
) ;
396
397
@@ -419,6 +420,7 @@ class AdminForth implements IAdminForth {
419
420
} else {
420
421
results [ dataSourceId ] = [ ] ;
421
422
}
423
+ await connector . close ( ) ;
422
424
} )
423
425
) ;
424
426
You can’t perform that action at this time.
0 commit comments