Skip to main content

openlark_platform/app_engine/apaas/v1/workspace/
mod.rs

1//! 工作空间相关 API
2//!
3//! 包含数据表、视图、枚举、SQL 执行等功能
4
5pub mod enum_mod;
6pub mod sql_commands;
7pub mod table;
8pub mod view;
9
10pub use enum_mod::enum_get;
11pub use enum_mod::list as enum_list;
12pub use sql_commands::SqlCommandsRequestBuilder;
13pub use table::list as table_list;
14pub use table::table_get;
15pub use view::views_get;
16
17use crate::PlatformConfig;
18use std::sync::Arc;
19
20/// workspace 资源服务(中间级,绑定 workspace_id)
21#[derive(Debug, Clone)]
22pub struct WorkspaceService {
23    config: Arc<PlatformConfig>,
24    workspace_id: String,
25}
26
27impl WorkspaceService {
28    /// 创建新的 workspace 服务
29    pub fn new(config: Arc<PlatformConfig>, workspace_id: impl Into<String>) -> Self {
30        Self {
31            config,
32            workspace_id: workspace_id.into(),
33        }
34    }
35
36    /// workspace.table 子资源
37    pub fn table(&self, table_name: impl Into<String>) -> table::TableService {
38        table::TableService::new(
39            self.config.as_ref().clone(),
40            self.workspace_id.clone(),
41            table_name,
42        )
43    }
44
45    /// workspace.view 子资源
46    pub fn view(&self, view_name: impl Into<String>) -> view::ViewService {
47        view::ViewService::new(
48            self.config.as_ref().clone(),
49            self.workspace_id.clone(),
50            view_name,
51        )
52    }
53
54    /// workspace.enum_mod 子资源
55    pub fn enum_mod(&self) -> enum_mod::EnumModService {
56        enum_mod::EnumModService::new(self.config.as_ref().clone(), self.workspace_id.clone())
57    }
58
59    /// 执行 SQL 命令
60    pub fn sql_commands(&self, sql: impl Into<String>) -> sql_commands::SqlCommandsRequestBuilder {
61        sql_commands::SqlCommandsRequestBuilder::new(
62            self.config.as_ref().clone(),
63            self.workspace_id.clone(),
64            sql,
65        )
66    }
67}