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
45    /// Runtime configuration or statistics statement.
46    Pragma {
47        /// PRAGMA name.
48        name: String,
49        /// Optional assignment value.
50        value: Option<PragmaValue>,
51    },
52
53    // DML
54    Select(Select),
55    Insert(Insert),
56    Update(Update),
57    Delete(Delete),
58}