Skip to main content

we_trust_sqlite/
transaction.rs

1use crate::connection::SqliteConnection;
2use yykv_types::{DsError, DsValue};
3
4type Result<T> = std::result::Result<T, DsError>;
5
6pub struct SqliteTransaction {
7    connection: SqliteConnection,
8}
9
10impl SqliteTransaction {
11    pub fn new(connection: SqliteConnection) -> Self {
12        Self { connection }
13    }
14
15    pub async fn execute(&self, sql: &str, params: &[DsValue]) -> Result<u64> {
16        self.connection.execute(sql, params).await
17    }
18
19    pub async fn query(&self, sql: &str, params: &[DsValue]) -> Result<Vec<DsValue>> {
20        self.connection.query(sql, params).await
21    }
22
23    pub async fn commit(self) -> Result<()> {
24        // SQLite native driver currently doesn't have explicit transaction support in writer
25        // but it performs atomic writes.
26        Ok(())
27    }
28
29    pub async fn rollback(self) -> Result<()> {
30        Ok(())
31    }
32}