Skip to content

Commit 1713219

Browse files
samarjeet818unknown
andauthored
feat: add transaction support (BEGIN/COMMIT/ROLLBACK) with WAL recovery (#137)
* feat: implement transaction support with WAL recovery Signed-off-by: unknown <010samarjeet@gamil.com> * fix: address transaction review feedback from CodeRabbit Signed-off-by: unknown <010samarjeet@gamil.com> --------- Signed-off-by: unknown <010samarjeet@gamil.com> Co-authored-by: unknown <010samarjeet@gamil.com>
1 parent a7e9927 commit 1713219

8 files changed

Lines changed: 633 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ All notable changes to NexumDB will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [Unreleased]
9+
10+
### Notes
11+
12+
* Transaction WAL currently uses a full `scan_all()` snapshot on `BEGIN` as an MVP implementation. A follow-up is planned to replace this with an incremental per-mutation undo/redo log for better scalability.
13+
* Transaction isolation is currently a single-active-transaction model per `Executor` and does not implement MVCC across multiple sessions yet.
14+
815
## [0.6.0](https://github.com/aviralgarg05/NexumDB/compare/v0.5.0...v0.6.0) (2026-02-06)
916

1017

nexum_cli/src/main.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ SQL COMMANDS:
4040
SPECIAL COMMANDS:
4141
SHOW TABLES List all tables
4242
DESCRIBE <table> Show table schema
43+
BEGIN / COMMIT / ROLLBACK Transaction control
4344
ASK <question> Natural language query
4445
EXPLAIN <query> Show query execution plan
4546
"#)]
@@ -245,6 +246,11 @@ fn print_help_summary() {
245246
"•".cyan(),
246247
"DESCRIBE <table>".yellow()
247248
);
249+
println!(
250+
" {} {} - Transaction control",
251+
"•".cyan(),
252+
"BEGIN / COMMIT / ROLLBACK".yellow()
253+
);
248254
println!(
249255
" {} {} - Show query plan",
250256
"•".cyan(),
@@ -290,6 +296,9 @@ fn print_full_help() {
290296
println!("{}", "Special Commands:".yellow().bold());
291297
println!(" {} - List all tables", "SHOW TABLES".cyan());
292298
println!(" {} - Show table schema", "DESCRIBE <table>".cyan());
299+
println!(" {} - Start transaction", "BEGIN".cyan());
300+
println!(" {} - Commit transaction", "COMMIT".cyan());
301+
println!(" {} - Roll back transaction", "ROLLBACK".cyan());
293302
println!(" {} - Natural language query", "ASK <question>".cyan());
294303
println!(" {} - Query execution plan", "EXPLAIN <query>".cyan());
295304
println!();
@@ -357,6 +366,28 @@ fn print_result(result: &ExecutionResult, json_output: bool) {
357366

358367
fn print_result_json(result: &ExecutionResult) {
359368
let json = match result {
369+
ExecutionResult::TransactionBegan { tx_id } => {
370+
serde_json::json!({
371+
"type": "transaction_began",
372+
"transaction_id": tx_id,
373+
"message": format!("Transaction {} started", tx_id)
374+
})
375+
}
376+
ExecutionResult::TransactionCommitted { tx_id, writes } => {
377+
serde_json::json!({
378+
"type": "transaction_committed",
379+
"transaction_id": tx_id,
380+
"writes": writes,
381+
"message": format!("Transaction {} committed ({} row mutation(s))", tx_id, writes)
382+
})
383+
}
384+
ExecutionResult::TransactionRolledBack { tx_id } => {
385+
serde_json::json!({
386+
"type": "transaction_rolled_back",
387+
"transaction_id": tx_id,
388+
"message": format!("Transaction {} rolled back", tx_id)
389+
})
390+
}
360391
ExecutionResult::Created { table } => {
361392
serde_json::json!({
362393
"type": "created",
@@ -446,6 +477,18 @@ fn print_result_json(result: &ExecutionResult) {
446477

447478
fn print_result_formatted(result: &ExecutionResult) {
448479
match result {
480+
ExecutionResult::TransactionBegan { tx_id } => {
481+
print_success(&format!("Transaction {} started", tx_id));
482+
}
483+
ExecutionResult::TransactionCommitted { tx_id, writes } => {
484+
print_success(&format!(
485+
"Transaction {} committed ({} row mutation(s))",
486+
tx_id, writes
487+
));
488+
}
489+
ExecutionResult::TransactionRolledBack { tx_id } => {
490+
print_success(&format!("Transaction {} rolled back", tx_id));
491+
}
449492
ExecutionResult::Created { table } => {
450493
print_success(&format!("Table '{}' created successfully", table));
451494
}

0 commit comments

Comments
 (0)