Skip to main content

cai_query/
error.rs

1//! Query error types
2
3use cai_core::Error as CoreError;
4
5/// Query-specific result type
6pub type QueryResult<T> = std::result::Result<T, QueryError>;
7
8/// Schema information returned by SHOW TABLES and DESCRIBE queries
9#[derive(Debug, Clone, serde::Serialize)]
10pub struct SchemaInfo {
11    /// Query type (SHOW_TABLES or DESCRIBE)
12    pub query_type: SchemaQueryType,
13    /// Table name (for DESCRIBE queries)
14    pub table_name: Option<String>,
15    /// List of tables (for SHOW TABLES)
16    pub tables: Vec<String>,
17    /// Column information (for DESCRIBE)
18    pub columns: Vec<ColumnInfo>,
19}
20
21/// Type of schema query
22#[derive(Debug, Clone, serde::Serialize)]
23pub enum SchemaQueryType {
24    /// SHOW TABLES query
25    ShowTables,
26    /// DESCRIBE table query
27    DescribeTable,
28}
29
30/// Column information for DESCRIBE queries
31#[derive(Debug, Clone, serde::Serialize)]
32pub struct ColumnInfo {
33    /// Column name
34    pub name: String,
35    /// Column data type
36    pub data_type: String,
37    /// Column description
38    pub description: String,
39}
40
41/// Query engine errors
42#[derive(Debug, thiserror::Error)]
43pub enum QueryError {
44    /// SQL parsing error
45    #[error("SQL parse error: {0}")]
46    ParseError(String),
47
48    /// Invalid table name
49    #[error("Invalid table name: {0}. Expected 'entries'")]
50    InvalidTable(String),
51
52    /// Invalid column name
53    #[error("Invalid column: {0}")]
54    InvalidColumn(String),
55
56    /// Invalid function
57    #[error("Invalid function: {0}")]
58    InvalidFunction(String),
59
60    /// Invalid operator
61    #[error("Invalid operator: {0}")]
62    InvalidOperator(String),
63
64    /// Type mismatch
65    #[error("Type mismatch: {0}")]
66    TypeMismatch(String),
67
68    /// Execution error
69    #[error("Execution error: {0}")]
70    Execution(String),
71
72    /// Core error
73    #[error("Core error: {0}")]
74    Core(#[from] CoreError),
75
76    /// Not supported
77    #[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}