0

The example of the transaction method on the doc.rs site just shows how to begin and end a transaction, so I think I should put every SQL execution inside these. Example:

let mut transaction = datastore.transaction(true, false).await?;

let sql = "CREATE task SET title = $title, due_date = $due_date, create_at = time::now();";

let data: BTreeMap<String, Value> = [
    ("title".into(), task.title.into()),
    ("due_date".into(), task.due_date.into()),
].into();

let res = datastore.execute(sql, &session, Some(data), false).await?;

transaction.commit().await?;

debug!("{:?}", res);

But the console only shows the following debug message from surrealdb: Executing: CREATE task SET title = $title, due_date = $due_date, create_at = time::now(). The transaction is never complete (commit).

When I get rid of the transaction, the SQL statement is executed normally and the console shows the value of res.

What is the right way to use Transaction?

Trí Phan
  • 1,123
  • 2
  • 15
  • 33

0 Answers0