From 357a24580b61204cf5ef652af7e877e42e6fd91f Mon Sep 17 00:00:00 2001 From: Dave Warnock Date: Mon, 1 Dec 2025 01:07:29 +0000 Subject: [PATCH] Improved transaction example It is more realistic to begin and commit the transaction outside the update function. --- bindings/rust/examples/example_struct.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bindings/rust/examples/example_struct.rs b/bindings/rust/examples/example_struct.rs index 42f0a5e20..a4001fdf9 100644 --- a/bindings/rust/examples/example_struct.rs +++ b/bindings/rust/examples/example_struct.rs @@ -15,13 +15,12 @@ async fn create_tables(conn: &Connection) -> Result<(), Error> { Ok(()) } -async fn insert_users(tx: Transaction<'_>) -> Result<(), Error> { +async fn insert_users(tx: &Transaction<'_>) -> Result<(), Error> { let mut stmt = tx .prepare("INSERT INTO users (email, age) VALUES (?1, ?2)") .await?; stmt.execute(["foo@example.com", &21.to_string()]).await?; stmt.execute(["bar@example.com", &22.to_string()]).await?; - tx.commit().await?; Ok(()) } @@ -53,7 +52,8 @@ async fn main() -> Result<(), Error> { create_tables(&conn).await?; let tx = conn.transaction().await?; - insert_users(tx).await?; + insert_users(&tx).await?; + tx.commit().await?; list_users(&conn).await?; Ok(())