intelli_shell/process/
query.rs

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