Skip to main content

alopex_sql/ast/
mod.rs

1pub mod ddl;
2pub mod dml;
3pub mod expr;
4pub mod span;
5
6pub use ddl::*;
7pub use dml::*;
8pub use expr::*;
9use serde::{Deserialize, Serialize};
10pub use span::{Location, Span, Spanned};
11
12/// Top-level SQL statement wrapper with span information.
13#[derive(Debug, Clone, Serialize, Deserialize)]
14pub struct Statement {
15    pub kind: StatementKind,
16    pub span: Span,
17}
18
19/// Value supplied to a PRAGMA statement.
20#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
21#[serde(untagged)]
22pub enum PragmaValue {
23    /// Integer setting.
24    Int(i64),
25    /// Text setting.
26    Text(String),
27}
28
29impl Spanned for Statement {
30    fn span(&self) -> Span {
31        self.span
32    }
33}
34
35#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(tag = "variant")]
37#[allow(clippy::large_enum_variant)]
38pub enum StatementKind {
39    // DDL
40    CreateTable(CreateTable),
41    DropTable(DropTable),
42    CreateIndex(CreateIndex),
43    DropIndex(DropIndex),
44    /// A Skulk-owned continuous aggregate definition carried but not executed by Alopex.
45    CreateContinuousAggregate(CreateContinuousAggregate),
46
47    /// Runtime configuration or statistics statement.
48    Pragma {
49        /// PRAGMA name.
50        name: String,
51        /// Optional assignment value.
52        value: Option<PragmaValue>,
53    },
54
55    // DML
56    Select(Select),
57    Values(Values),
58    Insert(Insert),
59    Update(Update),
60    Delete(Delete),
61}
62
63impl StatementKind {
64    /// Returns whether this statement produces a query result without mutating data.
65    pub const fn is_query(&self) -> bool {
66        matches!(self, Self::Select(_) | Self::Values(_))
67    }
68}