File tree Expand file tree Collapse file tree 1 file changed +38
-1
lines changed Expand file tree Collapse file tree 1 file changed +38
-1
lines changed Original file line number Diff line number Diff line change @@ -3469,7 +3469,44 @@ mod mssql {
3469
3469
}
3470
3470
3471
3471
async fn tables ( & self ) -> color_eyre:: Result < responses:: Tables > {
3472
- todo ! ( )
3472
+ let mut client = self . client . lock ( ) . await ;
3473
+
3474
+ let mut tables = client
3475
+ . query (
3476
+ r#"
3477
+ SELECT t.name AS name
3478
+ FROM sys.tables t
3479
+ JOIN sys.schemas s ON t.schema_id = s.schema_id
3480
+ WHERE s.name = SCHEMA_NAME();
3481
+ "# ,
3482
+ & [ ] ,
3483
+ )
3484
+ . await ?
3485
+ . into_row_stream ( )
3486
+ . try_filter_map ( |row| {
3487
+ let out = Ok ( row. get :: < & str , & str > ( "name" ) . map ( ToOwned :: to_owned) ) ;
3488
+ async { out }
3489
+ } )
3490
+ . map_ok ( |name| Count { name, count : 0 } )
3491
+ . filter_map ( |count| async { count. ok ( ) } )
3492
+ . collect :: < Vec < _ > > ( )
3493
+ . await ;
3494
+
3495
+ for count in tables. iter_mut ( ) {
3496
+ let sql = format ! ( "SELECT count(*) AS count FROM {}" , count. name) ;
3497
+
3498
+ count. count = client
3499
+ . query ( sql, & [ ] )
3500
+ . await ?
3501
+ . into_row ( )
3502
+ . await ?
3503
+ . and_then ( |row| row. get ( "count" ) )
3504
+ . ok_or_eyre ( "couldn't count rows" ) ?;
3505
+ }
3506
+
3507
+ tables. sort_by ( |a, b| b. count . cmp ( & a. count ) ) ;
3508
+
3509
+ Ok ( responses:: Tables { tables } )
3473
3510
}
3474
3511
3475
3512
async fn table ( & self , name : String ) -> color_eyre:: Result < responses:: Table > {
You can’t perform that action at this time.
0 commit comments