risingwave_frontend/catalog/system_catalog/rw_catalog/
rw_databases.rs1use risingwave_common::types::Fields;
16use risingwave_frontend_macro::system_catalog;
17use risingwave_pb::user::grant_privilege::Object;
18
19use crate::catalog::OwnedByUserCatalog;
20use crate::catalog::system_catalog::{SysCatalogReaderImpl, get_acl_items};
21use crate::error::Result;
22
23#[derive(Fields)]
24struct RwDatabases {
25 #[primary_key]
26 id: i32,
27 name: String,
28 owner: i32,
29 acl: Vec<String>,
30 resource_group: String,
31}
32
33#[system_catalog(table, "rw_catalog.rw_databases")]
34fn read(reader: &SysCatalogReaderImpl) -> Result<Vec<RwDatabases>> {
35 let catalog_reader = reader.catalog_reader.read_guard();
36 let user_reader = reader.user_info_reader.read_guard();
37 let users = user_reader.get_all_users();
38 let username_map = user_reader.get_user_name_map();
39
40 Ok(catalog_reader
41 .iter_databases()
42 .map(|db| RwDatabases {
43 id: db.id() as i32,
44 name: db.name().into(),
45 owner: db.owner() as i32,
46 acl: get_acl_items(&Object::DatabaseId(db.id()), false, &users, username_map),
47 resource_group: db.resource_group.clone(),
48 })
49 .collect())
50}