spacetimedb_sql_parser_2/parser/
errors.rs1use std::fmt::Display;
2
3use sqlparser::{
4 ast::{BinaryOperator, Expr, ObjectName, Query, Select, SelectItem, SetExpr, TableFactor, TableWithJoins, Value},
5 parser::ParserError,
6};
7use thiserror::Error;
8
9#[derive(Error, Debug)]
10pub enum SubscriptionUnsupported {
11 #[error("Unsupported SELECT: {0}")]
12 Select(Select),
13 #[error("Unsupported: {0}")]
14 Feature(String),
15 #[error("Unsupported: Non-SELECT queries")]
16 Dml,
17}
18
19impl SubscriptionUnsupported {
20 pub(crate) fn feature(expr: impl Display) -> Self {
21 Self::Feature(format!("{expr}"))
22 }
23}
24
25#[derive(Error, Debug)]
26pub enum SqlUnsupported {
27 #[error("Unsupported literal expression: {0}")]
28 Literal(Value),
29 #[error("Unsupported LIMIT expression: {0}")]
30 Limit(Expr),
31 #[error("Unsupported expression: {0}")]
32 Expr(Expr),
33 #[error("Unsupported binary operator: {0}")]
34 BinOp(BinaryOperator),
35 #[error("Unsupported projection: {0}")]
36 Projection(SelectItem),
37 #[error("Unsupported projection expression: {0}")]
38 ProjectionExpr(Expr),
39 #[error("Unsupported FROM expression: {0}")]
40 From(TableFactor),
41 #[error("Unsupported set operation: {0}")]
42 SetOp(SetExpr),
43 #[error("Unsupported INSERT expression: {0}")]
44 Insert(Query),
45 #[error("Unsupported INSERT value: {0}")]
46 InsertValue(Expr),
47 #[error("Unsupported table expression in DELETE: {0}")]
48 DeleteTable(TableWithJoins),
49 #[error("Unsupported column/variable assignment expression: {0}")]
50 Assignment(Expr),
51 #[error("Multi-part names are not supported: {0}")]
52 MultiPartName(ObjectName),
53 #[error("Unsupported: {0}")]
54 Feature(String),
55 #[error("Non-inner joins are not supported")]
56 JoinType,
57 #[error("Implicit joins are not supported")]
58 ImplicitJoins,
59 #[error("Mixed wildcard projections are not supported")]
60 MixedWildcardProject,
61 #[error("Multiple SQL statements are not supported")]
62 MultiStatement,
63 #[error("Multi-table DELETE is not supported")]
64 MultiTableDelete,
65}
66
67impl SqlUnsupported {
68 pub(crate) fn feature(expr: impl Display) -> Self {
69 Self::Feature(format!("{expr}"))
70 }
71}
72
73#[derive(Error, Debug)]
74pub enum SqlRequired {
75 #[error("A FROM clause is required")]
76 From,
77 #[error("Aliases are required for JOIN")]
78 JoinAlias,
79}
80
81#[derive(Error, Debug)]
82pub enum SqlParseError {
83 #[error(transparent)]
84 SqlUnsupported(#[from] SqlUnsupported),
85 #[error(transparent)]
86 SubscriptionUnsupported(#[from] SubscriptionUnsupported),
87 #[error(transparent)]
88 SqlRequired(#[from] SqlRequired),
89 #[error(transparent)]
90 ParserError(#[from] ParserError),
91}