hamelin_executor/
executor.rs

1use std::{error::Error, fmt::Debug};
2
3use async_trait::async_trait;
4use hamelin_lib::{
5    catalog::Catalog,
6    translation::{DMLTranslation, QueryTranslation, StatementTranslation},
7    TimeRange,
8};
9
10use crate::results::ResultSet;
11
12#[async_trait]
13pub trait Executor: Debug + Send + Sync {
14    // TODO: Should return an async iterator, or something, which allows batching.
15    async fn execute_query(&self, query: QueryTranslation) -> Result<ResultSet, ExecutorError>;
16    async fn execute_dml(&self, dml: DMLTranslation) -> Result<usize, ExecutorError>;
17    async fn execute(&self, statement: StatementTranslation) -> Result<(), ExecutorError>;
18    async fn resolve_time_range(&self, query: QueryTranslation)
19        -> Result<TimeRange, ExecutorError>;
20    async fn reflect_catalog(&self) -> Result<Catalog, ExecutorError>;
21}
22
23#[derive(Debug, thiserror::Error)]
24pub enum ExecutorError {
25    #[error("Server error: {0}")]
26    /// Think of this like a generic database 500.
27    ServerError(Box<dyn Error + Send + Sync + 'static>),
28
29    #[error("Query error: {0}")]
30    /// Your query was wrong. Try harder.
31    QueryError(Box<dyn Error + Send + Sync + 'static>),
32
33    #[error("Connection error: {0}")]
34    /// I can't connect to the place that you want to connect.
35    ConnectionError(Box<dyn Error + Send + Sync + 'static>),
36
37    #[error("Connection error: {0}")]
38    /// I can't even understand your configuration enough to build anything.
39    ConfigurationError(Box<dyn Error + Send + Sync + 'static>),
40
41    #[error("Unexpected result set: {0}")]
42    /// These were not the rows I expected.
43    UnexpectedResultSet(Box<dyn Error + Send + Sync + 'static>),
44}