TransactionManager

Struct TransactionManager 

Source
pub struct TransactionManager { /* private fields */ }
Expand description

Manages the state of database transactions in a thread-safe manner.

This struct wraps the TransactionState in an Arc<Mutex<>> to allow it to be shared across different parts of the application, such as between the REPL and other command handlers, while preventing race conditions.

Implementations§

Source§

impl TransactionManager

Source

pub fn new() -> Self

Creates a new TransactionManager with an initial state of None.

Source

pub fn begin_transaction(&self, conn: &Connection) -> Result<()>

Begins a new database transaction.

If a transaction is already active, it prints a warning and does nothing. Otherwise, it executes a BEGIN statement and sets the state to Active.

§Arguments
  • conn - A reference to the rusqlite::Connection.
Source

pub fn commit_transaction(&self, conn: &Connection) -> Result<()>

Commits the active database transaction.

If no transaction is active, it prints a message and does nothing. Otherwise, it executes a COMMIT statement and resets the state to None.

§Arguments
  • conn - A reference to the rusqlite::Connection.
Source

pub fn rollback_transaction(&self, conn: &Connection) -> Result<()>

Rolls back the active database transaction.

If no transaction is active, it prints a message and does nothing. Otherwise, it executes a ROLLBACK statement and resets the state to None.

§Arguments
  • conn - A reference to the rusqlite::Connection.
Source

pub fn is_active(&self) -> bool

Checks if a transaction is currently active.

§Returns

true if the transaction state is Active, false otherwise.

Source

pub fn show_status(&self)

Prints the current transaction status to the console.

Source

pub fn handle_sql_command(&self, conn: &Connection, sql: &str) -> Result<bool>

Intercepts and handles transaction-related SQL commands.

This method checks if the input SQL string matches known transaction control statements (BEGIN, COMMIT, ROLLBACK) or a DROP command. If a match is found, it calls the appropriate TransactionManager method and returns Ok(true). For DROP, it adds extra validation.

If the command is not a recognized transaction command, it returns Ok(false), indicating that the command should be executed as a standard SQL query.

§Arguments
  • conn - A reference to the rusqlite::Connection.
  • sql - The SQL command string to be processed.
§Returns

A Result<bool> which is Ok(true) if the command was handled, or Ok(false) if not.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V