use pyo3::exceptions::PyRuntimeError;
use pyo3::prelude::*;
use crate::core::single_file::SingleFileDB as RustSingleFileDB;
pub trait TransactionOps {
fn begin_impl(&self, read_only: bool) -> PyResult<i64>;
fn begin_bulk_impl(&self) -> PyResult<i64>;
fn commit_impl(&self) -> PyResult<()>;
fn rollback_impl(&self) -> PyResult<()>;
fn has_transaction_impl(&self) -> PyResult<bool>;
}
pub fn begin_single_file(db: &RustSingleFileDB, read_only: bool) -> PyResult<i64> {
let txid = db
.begin(read_only)
.map_err(|e| PyRuntimeError::new_err(format!("Failed to begin transaction: {e}")))?;
Ok(txid as i64)
}
pub fn begin_bulk_single_file(db: &RustSingleFileDB) -> PyResult<i64> {
let txid = db
.begin_bulk()
.map_err(|e| PyRuntimeError::new_err(format!("Failed to begin bulk transaction: {e}")))?;
Ok(txid as i64)
}
pub fn commit_single_file(db: &RustSingleFileDB) -> PyResult<()> {
db.commit()
.map_err(|e| PyRuntimeError::new_err(format!("Failed to commit: {e}")))
}
pub fn rollback_single_file(db: &RustSingleFileDB) -> PyResult<()> {
db.rollback()
.map_err(|e| PyRuntimeError::new_err(format!("Failed to rollback: {e}")))
}
#[cfg(test)]
mod tests {
}