risingwave_frontend/catalog/system_catalog/rw_catalog/
rw_databases.rs

1// Copyright 2025 RisingWave Labs
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use 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    barrier_interval_ms: Option<i32>,
32    checkpoint_frequency: Option<i64>,
33}
34
35#[system_catalog(table, "rw_catalog.rw_databases")]
36fn read(reader: &SysCatalogReaderImpl) -> Result<Vec<RwDatabases>> {
37    let catalog_reader = reader.catalog_reader.read_guard();
38    let user_reader = reader.user_info_reader.read_guard();
39    let users = user_reader.get_all_users();
40    let username_map = user_reader.get_user_name_map();
41
42    Ok(catalog_reader
43        .iter_databases()
44        .map(|db| RwDatabases {
45            id: db.id() as i32,
46            name: db.name().into(),
47            owner: db.owner() as i32,
48            acl: get_acl_items(&Object::DatabaseId(db.id()), false, &users, username_map),
49            resource_group: db.resource_group.clone(),
50            barrier_interval_ms: db.barrier_interval_ms.map(|v| v as i32),
51            checkpoint_frequency: db.checkpoint_frequency.map(|v| v as i64),
52        })
53        .collect())
54}