intelli_shell/process/
query.rs1use tokio_util::sync::CancellationToken;
2
3use super::{Process, ProcessOutput};
4use crate::{cli::QueryProcess, config::Config, errors::AppError, format_error, service::IntelliShellService};
5
6impl Process for QueryProcess {
7 async fn execute(
8 self,
9 config: Config,
10 service: IntelliShellService,
11 _cancellation_token: CancellationToken,
12 ) -> color_eyre::Result<ProcessOutput> {
13 let sql = self.sql.contents()?;
14 match service.query(sql).await {
15 Ok(output) => Ok(ProcessOutput::success().stdout(output)),
16 Err(AppError::UserFacing(err)) => Ok(ProcessOutput::fail().stderr(format_error!(config.theme, "{err}"))),
17 Err(AppError::Unexpected(report)) => Err(report),
18 }
19 }
20}