Skip to content

Commit

Permalink
Remove implicit transactions and thread the Tx instead (#65)
Browse files Browse the repository at this point in the history
* Remove implicit transactions and thread the Tx instead

* Split logic for proper Tx handling
  • Loading branch information
mamcx authored and cloutiertyler committed Aug 1, 2023
1 parent 2e7b2e9 commit 300e905
Show file tree
Hide file tree
Showing 14 changed files with 341 additions and 179 deletions.
30 changes: 5 additions & 25 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ termcolor = "1.2.0"
is-terminal = "0.4"
futures = "0.3"
tempfile = "3.3"
rustyline = { version = "11.0.0", features = [] }
rustyline = { version = "12.0.0", features = [] }
syntect = { version = "5.0.0", default-features = false, features = ["default-fancy"]}
wasmbin = "0.6"
itertools = "0.10"
Expand Down
5 changes: 1 addition & 4 deletions crates/cli/src/subcommands/repl.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::api::{ClientApi, Connection};
use crate::sql::run_sql;
use colored::*;
use std::io::Write;

use rustyline::completion::Completer;
use rustyline::error::ReadlineError;
Expand Down Expand Up @@ -64,9 +63,7 @@ pub async fn exec(con: Connection) -> Result<(), anyhow::Error> {
Ok(line) => match line.as_str() {
".exit" => break,
".clear" => {
//todo: this could not work on windows
print!("{esc}[2J{esc}[1;1H", esc = 27 as char);
std::io::stdout().flush().ok();
rl.clear_screen().ok();
}
sql => {
rl.add_history_entry(sql).ok();
Expand Down
8 changes: 8 additions & 0 deletions crates/core/src/db/relational_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,14 @@ impl RelationalDB {
{
let mut tx = self.begin_tx();
let res = f(&mut tx);
self.finish_tx(tx, res)
}

/// Perform the transactional logic for the `tx` according to the `res`
pub fn finish_tx<A, E>(&self, tx: MutTxId, res: Result<A, E>) -> Result<A, E>
where
E: From<DBError>,
{
if res.is_err() {
self.rollback_tx(tx);
} else {
Expand Down
Loading

0 comments on commit 300e905

Please sign in to comment.