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