public async Task <List <string> > GetDatabases(string filter) { if (string.IsNullOrWhiteSpace(filter)) { filter = "*"; } List <string> databases = new List <string>(); filter = FilterUtility.ConvertSearchPatternToRegex(filter); using (var conn = new MySqlConnection(ConnectionString)) { await conn.OpenAsync(); var cmd = conn.CreateCommand(); cmd.CommandText = "show databases"; using (var reader = await cmd.ExecuteReaderAsync()) { while (await reader.ReadAsync()) { var dbname = reader[0].ToString(); if (Regex.IsMatch(dbname, filter, RegexOptions.IgnoreCase)) { databases.Add(dbname); } } } } return(databases); }
public async Task <List <TableInfo> > GetTables(string filter) { filter = FilterUtility.ConvertSearchPatternToRegex(filter); List <TableInfo> tables = new List <TableInfo>(); using (var conn = new NpgsqlConnection(dataSourceInfo.ConnectionString)) { await conn.OpenAsync(); var tableSchema = conn.GetSchema("Tables"); foreach (DataRow r in tableSchema.Rows) { //var schema = r["table_schema"]; var table = r["table_name"].ToString(); var type = r["table_type"].ToString(); if (Regex.IsMatch(table, filter, RegexOptions.IgnoreCase)) { tables.Add(new TableInfo() { TableName = table, TableType = type }); } } } return(tables); }