Skip to main content

openlark_platform/spark/v1/app/
sql_commands.rs

1//! 执行 SQL
2//!
3//! docPath:
4
5use openlark_core::{
6    SDKResult, api::ApiRequest, config::Config, http::Transport, req_option::RequestOption,
7    validate_required,
8};
9use std::sync::Arc;
10
11/// 执行 SQL请求。
12#[derive(Debug, Clone)]
13pub struct AppSqlCommandsRequest {
14    config: Arc<Config>,
15    app_id: String,
16}
17
18impl AppSqlCommandsRequest {
19    /// 创建请求。
20    pub fn new(config: Arc<Config>) -> Self {
21        Self {
22            config,
23            app_id: String::new(),
24        }
25    }
26
27    /// 设置路径参数 `app_id`。
28    pub fn app_id(mut self, app_id: impl Into<String>) -> Self {
29        self.app_id = app_id.into();
30        self
31    }
32
33    /// 执行请求。
34    pub async fn execute(self, body: serde_json::Value) -> SDKResult<serde_json::Value> {
35        self.execute_with_options(body, RequestOption::default())
36            .await
37    }
38
39    /// 使用指定请求选项执行请求。
40    pub async fn execute_with_options(
41        self,
42        body: serde_json::Value,
43        option: RequestOption,
44    ) -> SDKResult<serde_json::Value> {
45        validate_required!(self.app_id, "app_id 不能为空");
46        let path = format!("/open-apis/spark/v1/apps/{}/sql_commands", self.app_id);
47        let req: ApiRequest<serde_json::Value> = ApiRequest::post(path).body(body);
48        Transport::request_typed(req, &self.config, Some(option), "执行 SQL").await
49    }
50}
51
52#[cfg(test)]
53mod tests {
54    use super::*;
55
56    #[test]
57    fn builder_initializes() {
58        let config = Arc::new(Config::default());
59        let _request = AppSqlCommandsRequest::new(config);
60    }
61}