Skip to content

Commit

Permalink
Deprecate synchronous transactions (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
smklein authored Oct 6, 2023
1 parent 1446f7e commit 8caa7d3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 24 deletions.
21 changes: 6 additions & 15 deletions examples/usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,16 @@ async fn main() {
.unwrap();

// Transaction with multiple operations
conn.transaction(|conn| {
conn.transaction_async(|conn| async move {
diesel::insert_into(dsl::users)
.values((dsl::id.eq(0), dsl::name.eq("Jim")))
.execute(conn)
.execute_async(&conn)
.await
.unwrap();
diesel::insert_into(dsl::users)
.values((dsl::id.eq(1), dsl::name.eq("Another Jim")))
.execute(conn)
.execute_async(&conn)
.await
.unwrap();
Ok::<(), ConnectionError>(())
})
Expand All @@ -103,23 +105,12 @@ async fn main() {

// Transaction returning custom error types.
let _: MyError = conn
.transaction(|_| {
.transaction_async(|_| async {
return Err::<(), MyError>(MyError::Other {});
})
.await
.unwrap_err();

// Asynchronous transaction.
conn.transaction_async(|conn| async move {
diesel::update(dsl::users)
.filter(dsl::id.eq(0))
.set(dsl::name.eq("Let's change the name again"))
.execute_async(&conn)
.await
})
.await
.unwrap();

// Access the result via OptionalExtension
assert!(dsl::users
.filter(dsl::id.eq(12345))
Expand Down
9 changes: 0 additions & 9 deletions src/async_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,6 @@ where
.unwrap() // Propagate panics
}

async fn transaction<R, E, Func>(&self, f: Func) -> Result<R, E>
where
R: Send + 'static,
E: From<DieselError> + Send + 'static,
Func: FnOnce(&mut Conn) -> Result<R, E> + Send + 'static,
{
self.run(|conn| conn.transaction(|c| f(c))).await
}

async fn transaction_async<R, E, Func, Fut, 'a>(&'a self, f: Func) -> Result<R, E>
where
R: Send + 'static,
Expand Down

0 comments on commit 8caa7d3

Please sign in to comment.