Skip to content

Commit 3578301

Browse files
committed
Publish v0.1.7
- add Trans::{commit, rollback}
1 parent 7807fa6 commit 3578301

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

chuchi-postgres/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "chuchi-postgres"
33
description = "A wrapper around tokio-postgres to simplify working with Postgres databases."
4-
version = "0.1.6"
4+
version = "0.1.7"
55
authors = ["Sören Meier <info@soerenmeier.ch>"]
66
homepage = "https://chuchi.dev/"
77
repository = "https://github.com/chuchi-dev/chuchi-postgres"

chuchi-postgres/src/db.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,26 @@ impl<'a> Trans<'a> {
120120
pg: self.pg.as_ref().map(|pg| pg.connection()),
121121
}
122122
}
123+
124+
/// Commit the transaction.
125+
///
126+
/// ## Note
127+
/// Does nothing if it contains a memory Conn
128+
pub async fn commit(self) -> Result<(), Error> {
129+
match self.pg {
130+
Some(pg) => pg.commit().await,
131+
None => Ok(()),
132+
}
133+
}
134+
135+
/// Rollback the transaction.
136+
///
137+
/// ## Panics
138+
/// If the transaction is not set / this is a memory Conn
139+
pub async fn rollback(self) -> Result<(), Error> {
140+
match self.pg {
141+
Some(pg) => pg.commit().await,
142+
None => panic!("rollback not supported"),
143+
}
144+
}
123145
}

0 commit comments

Comments
 (0)