@@ -90,24 +90,39 @@ export async function connect(config: ConnectionConfig): Promise<Connector> {
9090 }
9191 } ,
9292
93- async getSchema ( database_ ?: string ) : Promise < SchemaColumn [ ] > {
94- const db = database_ ?? database
93+ async listSchemas ( ) : Promise < string [ ] > {
94+ const { rows } = await httpQuery ( "SHOW DATABASES" )
95+ return rows . map ( ( r ) => String ( r [ 0 ] ) )
96+ } ,
97+
98+ async listTables ( schema : string ) : Promise < Array < { name : string ; type : string } > > {
99+ const { rows } = await httpQuery ( `
100+ SELECT name, engine
101+ FROM system.tables
102+ WHERE database = '${ schema } '
103+ ORDER BY name
104+ ` )
105+ return rows . map ( ( r ) => ( {
106+ name : String ( r [ 0 ] ) ,
107+ type : String ( r [ 1 ] ) . toLowerCase ( ) . includes ( "view" ) ? "view" : "table" ,
108+ } ) )
109+ } ,
110+
111+ async describeTable ( schema : string , table : string ) : Promise < SchemaColumn [ ] > {
95112 const { rows } = await httpQuery ( `
96113 SELECT
97- table_name,
98114 column_name,
99115 data_type,
100116 is_nullable
101117 FROM information_schema.columns
102- WHERE table_schema = '${ db } '
103- ORDER BY table_name, ordinal_position
118+ WHERE table_schema = '${ schema } '
119+ AND table_name = '${ table } '
120+ ORDER BY ordinal_position
104121 ` )
105-
106122 return rows . map ( ( row ) => ( {
107- table_name : String ( row [ 0 ] ) ,
108- name : String ( row [ 1 ] ) ,
109- data_type : String ( row [ 2 ] ) ,
110- nullable : row [ 3 ] === "YES" || row [ 3 ] === "1" ,
123+ name : String ( row [ 0 ] ) ,
124+ data_type : String ( row [ 1 ] ) ,
125+ nullable : row [ 2 ] === "YES" || row [ 2 ] === "1" ,
111126 } ) )
112127 } ,
113128
0 commit comments