@@ -443,6 +443,33 @@ impl Client {
443
443
Ok ( Transaction :: new ( & mut self . runtime , transaction) )
444
444
}
445
445
446
+ /// Returns a builder for a transaction with custom settings.
447
+ ///
448
+ /// Unlike the `transaction` method, the builder can be used to control the transaction's isolation level and other
449
+ /// attributes.
450
+ ///
451
+ /// # Examples
452
+ ///
453
+ /// ```no_run
454
+ /// use postgres::{Client, IsolationLevel, NoTls};
455
+ ///
456
+ /// # fn main() -> Result<(), postgres::Error> {
457
+ /// let mut client = Client::connect("host=localhost user=postgres", NoTls)?;
458
+ ///
459
+ /// let mut transaction = client.build_transaction()
460
+ /// .isolation_level(IsolationLevel::RepeatableRead)
461
+ /// .start()?;
462
+ /// transaction.execute("UPDATE foo SET bar = 10", &[])?;
463
+ /// // ...
464
+ ///
465
+ /// transaction.commit()?;
466
+ /// # Ok(())
467
+ /// # }
468
+ /// ```
469
+ pub fn build_transaction ( & mut self ) -> TransactionBuilder < ' _ > {
470
+ TransactionBuilder :: new ( & mut self . runtime , self . client . build_transaction ( ) )
471
+ }
472
+
446
473
/// Constructs a cancellation token that can later be used to request
447
474
/// cancellation of a query running on this connection.
448
475
///
@@ -483,33 +510,6 @@ impl Client {
483
510
CancelToken :: new ( self . client . cancel_token ( ) )
484
511
}
485
512
486
- /// Returns a builder for a transaction with custom settings.
487
- ///
488
- /// Unlike the `transaction` method, the builder can be used to control the transaction's isolation level and other
489
- /// attributes.
490
- ///
491
- /// # Examples
492
- ///
493
- /// ```no_run
494
- /// use postgres::{Client, IsolationLevel, NoTls};
495
- ///
496
- /// # fn main() -> Result<(), postgres::Error> {
497
- /// let mut client = Client::connect("host=localhost user=postgres", NoTls)?;
498
- ///
499
- /// let mut transaction = client.build_transaction()
500
- /// .isolation_level(IsolationLevel::RepeatableRead)
501
- /// .start()?;
502
- /// transaction.execute("UPDATE foo SET bar = 10", &[])?;
503
- /// // ...
504
- ///
505
- /// transaction.commit()?;
506
- /// # Ok(())
507
- /// # }
508
- /// ```
509
- pub fn build_transaction ( & mut self ) -> TransactionBuilder < ' _ > {
510
- TransactionBuilder :: new ( & mut self . runtime , self . client . build_transaction ( ) )
511
- }
512
-
513
513
/// Determines if the client's connection has already closed.
514
514
///
515
515
/// If this returns `true`, the client is no longer usable.
0 commit comments