11use std:: rc:: Rc ;
22use sea_query:: { Expr , Iden , Order , Query , SelectStatement } ;
33use crate :: sqlx_types:: { Row , mysql:: MySqlRow } ;
4- use super :: { InformationSchema , SchemaQueryBuilder } ;
4+ use super :: { InformationSchema , SchemaQueryBuilder , CharacterSetFields } ;
55
66#[ derive( Debug , sea_query:: Iden ) ]
77/// Ref: https://dev.mysql.com/doc/refman/8.0/en/information-schema-tables-table.html
@@ -43,13 +43,15 @@ pub struct TableQueryResult {
4343 pub table_name : String ,
4444 pub engine : String ,
4545 pub auto_increment : Option < u64 > ,
46+ pub table_char_set : String ,
4647 pub table_collation : String ,
4748 pub table_comment : String ,
4849 pub create_options : String ,
4950}
5051
5152impl SchemaQueryBuilder {
5253 pub fn query_tables ( & self , schema : Rc < dyn Iden > ) -> SelectStatement {
54+ type Schema = InformationSchema ;
5355 Query :: select ( )
5456 . columns ( vec ! [
5557 TablesFields :: TableName ,
@@ -59,7 +61,13 @@ impl SchemaQueryBuilder {
5961 TablesFields :: TableComment ,
6062 TablesFields :: CreateOptions ,
6163 ] )
62- . from ( ( InformationSchema :: Schema , InformationSchema :: Tables ) )
64+ . column ( ( Schema :: CollationCharacterSet , CharacterSetFields :: CharacterSetName ) )
65+ . from ( ( Schema :: Schema , Schema :: Tables ) )
66+ . left_join (
67+ ( Schema :: Schema , Schema :: CollationCharacterSet ) ,
68+ Expr :: tbl ( Schema :: CollationCharacterSet , CharacterSetFields :: CollationName )
69+ . equals ( Schema :: Tables , TablesFields :: TableCollation )
70+ )
6371 . and_where ( Expr :: col ( TablesFields :: TableSchema ) . eq ( schema. to_string ( ) ) )
6472 . and_where ( Expr :: col ( TablesFields :: TableType ) . eq ( TableType :: BaseTable . to_string ( ) ) )
6573 . order_by ( TablesFields :: TableName , Order :: Asc )
@@ -77,6 +85,7 @@ impl From<&MySqlRow> for TableQueryResult {
7785 table_collation : row. get ( 3 ) ,
7886 table_comment : row. get ( 4 ) ,
7987 create_options : row. get ( 5 ) ,
88+ table_char_set : row. get ( 6 ) ,
8089 }
8190 }
8291}
0 commit comments