use openlark_core::{
SDKResult, api::ApiRequest, config::Config, http::Transport, req_option::RequestOption,
validate_required,
};
use std::sync::Arc;
#[derive(Debug, Clone)]
pub struct AppSqlCommandsRequest {
config: Arc<Config>,
app_id: String,
}
impl AppSqlCommandsRequest {
pub fn new(config: Arc<Config>) -> Self {
Self {
config,
app_id: String::new(),
}
}
pub fn app_id(mut self, app_id: impl Into<String>) -> Self {
self.app_id = app_id.into();
self
}
pub async fn execute(self, body: serde_json::Value) -> SDKResult<serde_json::Value> {
self.execute_with_options(body, RequestOption::default())
.await
}
pub async fn execute_with_options(
self,
body: serde_json::Value,
option: RequestOption,
) -> SDKResult<serde_json::Value> {
validate_required!(self.app_id, "app_id 不能为空");
let path = format!("/open-apis/spark/v1/apps/{}/sql_commands", self.app_id);
let req: ApiRequest<serde_json::Value> = ApiRequest::post(path).body(body);
Transport::request_typed(req, &self.config, Some(option), "执行 SQL").await
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn builder_initializes() {
let config = Arc::new(Config::default());
let _request = AppSqlCommandsRequest::new(config);
}
}