spacetimedb_sql_parser/parser/
errors.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
use std::fmt::Display;

use sqlparser::{
    ast::{BinaryOperator, Expr, ObjectName, Query, Select, SelectItem, SetExpr, TableFactor, TableWithJoins, Value},
    parser::ParserError,
};
use thiserror::Error;

#[derive(Error, Debug)]
pub enum SubscriptionUnsupported {
    #[error("Unsupported SELECT: {0}")]
    Select(Select),
    #[error("Unsupported: {0}")]
    Feature(String),
    #[error("Unsupported: Non-SELECT queries")]
    Dml,
}

impl SubscriptionUnsupported {
    pub(crate) fn feature(expr: impl Display) -> Self {
        Self::Feature(format!("{expr}"))
    }
}

#[derive(Error, Debug)]
pub enum SqlUnsupported {
    #[error("Unsupported literal expression: {0}")]
    Literal(Value),
    #[error("Unsupported LIMIT expression: {0}")]
    Limit(Expr),
    #[error("Unsupported expression: {0}")]
    Expr(Expr),
    #[error("Unsupported binary operator: {0}")]
    BinOp(BinaryOperator),
    #[error("Unsupported projection: {0}")]
    Projection(SelectItem),
    #[error("Unsupported projection expression: {0}")]
    ProjectionExpr(Expr),
    #[error("Unsupported FROM expression: {0}")]
    From(TableFactor),
    #[error("Unsupported set operation: {0}")]
    SetOp(SetExpr),
    #[error("Unsupported INSERT expression: {0}")]
    Insert(Query),
    #[error("Unsupported INSERT value: {0}")]
    InsertValue(Expr),
    #[error("Unsupported table expression in DELETE: {0}")]
    DeleteTable(TableWithJoins),
    #[error("Unsupported column/variable assignment expression: {0}")]
    Assignment(Expr),
    #[error("Multi-part names are not supported: {0}")]
    MultiPartName(ObjectName),
    #[error("Unsupported: {0}")]
    Feature(String),
    #[error("Non-inner joins are not supported")]
    JoinType,
    #[error("Implicit joins are not supported")]
    ImplicitJoins,
    #[error("Mixed wildcard projections are not supported")]
    MixedWildcardProject,
    #[error("Multiple SQL statements are not supported")]
    MultiStatement,
    #[error("Multi-table DELETE is not supported")]
    MultiTableDelete,
}

impl SqlUnsupported {
    pub(crate) fn feature(expr: impl Display) -> Self {
        Self::Feature(format!("{expr}"))
    }
}

#[derive(Error, Debug)]
pub enum SqlRequired {
    #[error("A FROM clause is required")]
    From,
    #[error("Aliases are required for JOIN")]
    JoinAlias,
}

#[derive(Error, Debug)]
pub enum SqlParseError {
    #[error(transparent)]
    SqlUnsupported(#[from] SqlUnsupported),
    #[error(transparent)]
    SubscriptionUnsupported(#[from] SubscriptionUnsupported),
    #[error(transparent)]
    SqlRequired(#[from] SqlRequired),
    #[error(transparent)]
    ParserError(#[from] ParserError),
}