Skip to content

How to use rust sdk to write a transaction? #4090

Answered by Dhghomon
HaoYang670 asked this question in Q&A
Discussion options

You must be logged in to vote

There's no dedicated method for a transaction but you can put multiple statements into a single query, including inside a transaction:

let mut query = db.query("begin; create person; create person; throw 'Bad transaction!'; commit;").await.unwrap();
    println!("Number of statements: {}\nReturned: {query:#?}", query.num_statements());
    let errs = query.take_errors();
    println!("Errors: {errs:?}");

Is that enough for your use case?

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@HaoYang670
Comment options

Answer selected by HaoYang670
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants