we_trust_sqlserver/
transaction.rs1use crate::connection::SqlServerConnection;
2use yykv_types::{DsError, DsValue};
3
4type Result<T> = std::result::Result<T, DsError>;
5
6pub struct SqlServerTransaction {
7 connection: SqlServerConnection,
8}
9
10impl SqlServerTransaction {
11 pub fn new(connection: SqlServerConnection) -> 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 self.connection.execute("COMMIT", &[]).await?;
25 Ok(())
26 }
27
28 pub async fn rollback(self) -> Result<()> {
29 self.connection.execute("ROLLBACK", &[]).await?;
30 Ok(())
31 }
32}