1use cai_core::Error as CoreError;
4
5pub type QueryResult<T> = std::result::Result<T, QueryError>;
7
8#[derive(Debug, Clone, serde::Serialize)]
10pub struct SchemaInfo {
11 pub query_type: SchemaQueryType,
13 pub table_name: Option<String>,
15 pub tables: Vec<String>,
17 pub columns: Vec<ColumnInfo>,
19}
20
21#[derive(Debug, Clone, serde::Serialize)]
23pub enum SchemaQueryType {
24 ShowTables,
26 DescribeTable,
28}
29
30#[derive(Debug, Clone, serde::Serialize)]
32pub struct ColumnInfo {
33 pub name: String,
35 pub data_type: String,
37 pub description: String,
39}
40
41#[derive(Debug, thiserror::Error)]
43pub enum QueryError {
44 #[error("SQL parse error: {0}")]
46 ParseError(String),
47
48 #[error("Invalid table name: {0}. Expected 'entries'")]
50 InvalidTable(String),
51
52 #[error("Invalid column: {0}")]
54 InvalidColumn(String),
55
56 #[error("Invalid function: {0}")]
58 InvalidFunction(String),
59
60 #[error("Invalid operator: {0}")]
62 InvalidOperator(String),
63
64 #[error("Type mismatch: {0}")]
66 TypeMismatch(String),
67
68 #[error("Execution error: {0}")]
70 Execution(String),
71
72 #[error("Core error: {0}")]
74 Core(#[from] CoreError),
75
76 #[error("Not supported: {0}")]
78 NotSupported(String),
79}
80
81impl From<sqlparser::parser::ParserError> for QueryError {
82 fn from(err: sqlparser::parser::ParserError) -> Self {
83 QueryError::ParseError(err.to_string())
84 }
85}