Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate synchronous transactions #55

Merged
merged 1 commit into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading