fix(oceanbase): show oracle mode schemas in sidebar

This commit is contained in:
t8y2 committed 2026-06-26 02:03:00 +08:00
1 parent 2dc71548c3
commit dff94d60f5
10 files changed
+73 -23

No files matched your search

+16 -8
View File
@@ -29,21 +29,24 @@ fn get_opt_i32(row: &mysql_async::Row, idx: usize) -> Option<i32> {
row_get::<i32, _>(row, idx).or_else(|| row_get::<i64, _>(row, idx).and_then(|v| i32::try_from(v).ok()))
}
fn list_user_schemas_sql() -> &'static str {
"SELECT USERNAME FROM ALL_USERS \
WHERE USERNAME NOT IN ('SYS','LBACSYS','__public') \
ORDER BY USERNAME"
}
pub async fn list_databases(pool: &mysql_async::Pool) -> Result<Vec<DatabaseInfo>, String> {
let mut conn = pool.get_conn().await.map_err(|e| e.to_string())?;
let result = conn
.query_iter(
"SELECT USERNAME FROM ALL_USERS \
WHERE USERNAME NOT IN ('SYS','LBACSYS','ORAAUDITOR','__public') \
ORDER BY USERNAME",
)
.await
.map_err(|e| e.to_string())?;
let result = conn.query_iter(list_user_schemas_sql()).await.map_err(|e| e.to_string())?;
let rows: Vec<mysql_async::Row> = result.collect_and_drop().await.map_err(|e| e.to_string())?;
Ok(rows.iter().map(|row| DatabaseInfo { name: get_str(row, 0) }).collect())
}
pub async fn list_schemas(pool: &mysql_async::Pool) -> Result<Vec<String>, String> {
list_databases(pool).await.map(|databases| databases.into_iter().map(|database| database.name).collect())
}
pub async fn list_tables(pool: &mysql_async::Pool, schema: &str) -> Result<Vec<TableInfo>, String> {
let sql = format!(
"SELECT TABLE_NAME, 'TABLE' AS TABLE_TYPE FROM ALL_TABLES WHERE OWNER = {s} \
@@ -289,4 +292,9 @@ mod tests {
assert!(sql.contains("'PACKAGE'"));
assert!(sql.contains("'PACKAGE BODY'"));
}
#[test]
fn ob_oracle_user_schema_sql_keeps_auditor_schema_available() {
assert!(!list_user_schemas_sql().contains("ORAAUDITOR"));
}
}
+3
View File
@@ -714,6 +714,9 @@ async fn list_schemas_once(
let pool = connections.get(&pool_key).ok_or("Pool not found")?;
match pool {
PoolKind::Mysql(p, mode) if *mode == MysqlMode::OceanBaseOracle => db::ob_oracle::list_schemas(p)
.await
.map(|schemas| filter_visible_schema_names(schemas, visible_schema_filter.as_deref())),
PoolKind::Postgres(p) => db::postgres::list_schemas(p)
.await
.map(|schemas| filter_visible_schema_names(schemas, visible_schema_filter.as_deref())),
@@ -22,6 +22,7 @@ pub(in crate::schema) async fn list_databases(
pub(in crate::schema) async fn list_schemas(pool: &PoolKind) -> Result<Vec<String>, String> {
match pool {
PoolKind::Mysql(p, mode) if *mode == MysqlMode::OceanBaseOracle => db::ob_oracle::list_schemas(p).await,
PoolKind::Postgres(p) => db::postgres::list_schemas(p).await,
_ => Ok(vec![]),
}