vibesql_ast/ddl/
transaction.rs

1//! Transaction control DDL operations
2//!
3//! This module contains AST nodes for transaction control statements:
4//! - BEGIN TRANSACTION
5//! - COMMIT
6//! - ROLLBACK
7//! - SAVEPOINT
8//! - SET TRANSACTION
9
10/// Durability hint for a transaction
11///
12/// Controls how the transaction's changes are persisted.
13/// This mirrors `TransactionDurability` in the storage crate.
14#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
15pub enum DurabilityHint {
16    /// Use the database's default durability mode
17    #[default]
18    Default,
19    /// Force durable commit (fsync on commit)
20    Durable,
21    /// Allow lazy commit (batched sync)
22    Lazy,
23    /// Force volatile (no WAL) for this transaction
24    Volatile,
25}
26
27impl DurabilityHint {
28    /// Convert to SQL hint string for use with storage layer
29    pub fn as_sql_hint(&self) -> &'static str {
30        match self {
31            DurabilityHint::Default => "DEFAULT",
32            DurabilityHint::Durable => "DURABLE",
33            DurabilityHint::Lazy => "LAZY",
34            DurabilityHint::Volatile => "VOLATILE",
35        }
36    }
37}
38
39/// BEGIN TRANSACTION statement
40#[derive(Debug, Clone, PartialEq, Default)]
41pub struct BeginStmt {
42    /// Optional durability hint for this transaction
43    pub durability: DurabilityHint,
44}
45
46/// COMMIT statement
47#[derive(Debug, Clone, PartialEq)]
48pub struct CommitStmt;
49
50/// ROLLBACK statement
51#[derive(Debug, Clone, PartialEq)]
52pub struct RollbackStmt;
53
54/// SAVEPOINT statement
55#[derive(Debug, Clone, PartialEq)]
56pub struct SavepointStmt {
57    pub name: String,
58}
59
60/// ROLLBACK TO SAVEPOINT statement
61#[derive(Debug, Clone, PartialEq)]
62pub struct RollbackToSavepointStmt {
63    pub name: String,
64}
65
66/// RELEASE SAVEPOINT statement
67#[derive(Debug, Clone, PartialEq)]
68pub struct ReleaseSavepointStmt {
69    pub name: String,
70}
71
72/// Transaction isolation level
73#[derive(Debug, Clone, PartialEq)]
74pub enum IsolationLevel {
75    Serializable,
76}
77
78/// Transaction access mode
79#[derive(Debug, Clone, PartialEq)]
80pub enum TransactionAccessMode {
81    ReadOnly,
82    ReadWrite,
83}
84
85/// SET TRANSACTION statement (SQL:1999 Feature E152)
86#[derive(Debug, Clone, PartialEq)]
87pub struct SetTransactionStmt {
88    pub local: bool, // true for SET LOCAL TRANSACTION, false for SET TRANSACTION
89    pub isolation_level: Option<IsolationLevel>,
90    pub access_mode: Option<TransactionAccessMode>,
91}