use cai_core::Error as CoreError;
pub type QueryResult<T> = std::result::Result<T, QueryError>;
#[derive(Debug, Clone, serde::Serialize)]
pub struct SchemaInfo {
pub query_type: SchemaQueryType,
pub table_name: Option<String>,
pub tables: Vec<String>,
pub columns: Vec<ColumnInfo>,
}
#[derive(Debug, Clone, serde::Serialize)]
pub enum SchemaQueryType {
ShowTables,
DescribeTable,
}
#[derive(Debug, Clone, serde::Serialize)]
pub struct ColumnInfo {
pub name: String,
pub data_type: String,
pub description: String,
}
#[derive(Debug, thiserror::Error)]
pub enum QueryError {
#[error("SQL parse error: {0}")]
ParseError(String),
#[error("Invalid table name: {0}. Expected 'entries'")]
InvalidTable(String),
#[error("Invalid column: {0}")]
InvalidColumn(String),
#[error("Invalid function: {0}")]
InvalidFunction(String),
#[error("Invalid operator: {0}")]
InvalidOperator(String),
#[error("Type mismatch: {0}")]
TypeMismatch(String),
#[error("Execution error: {0}")]
Execution(String),
#[error("Core error: {0}")]
Core(#[from] CoreError),
#[error("Not supported: {0}")]
NotSupported(String),
}
impl From<sqlparser::parser::ParserError> for QueryError {
fn from(err: sqlparser::parser::ParserError) -> Self {
QueryError::ParseError(err.to_string())
}
}