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;
17
18use crate::catalog::OwnedByUserCatalog;
19use crate::catalog::system_catalog::{SysCatalogReaderImpl, get_acl_items};
20use crate::error::Result;
21
22#[derive(Fields)]
23struct RwDatabases {
24    #[primary_key]
25    id: i32,
26    name: String,
27    owner: i32,
28    acl: Vec<String>,
29    resource_group: String,
30    barrier_interval_ms: Option<i32>,
31    checkpoint_frequency: Option<i64>,
32}
33
34#[system_catalog(table, "rw_catalog.rw_databases")]
35fn read(reader: &SysCatalogReaderImpl) -> Result<Vec<RwDatabases>> {
36    let catalog_reader = reader.catalog_reader.read_guard();
37    let user_reader = reader.user_info_reader.read_guard();
38    let users = user_reader.get_all_users();
39    let username_map = user_reader.get_user_name_map();
40
41    Ok(catalog_reader
42        .iter_databases()
43        .map(|db| RwDatabases {
44            id: db.id().as_i32_id(),
45            name: db.name().into(),
46            owner: db.owner() as i32,
47            acl: get_acl_items(db.id(), false, &users, username_map),
48            resource_group: db.resource_group.clone(),
49            barrier_interval_ms: db.barrier_interval_ms.map(|v| v as i32),
50            checkpoint_frequency: db.checkpoint_frequency.map(|v| v as i64),
51        })
52        .collect())
53}