diff --git a/postgres/src/client.rs b/postgres/src/client.rs index 90834508..fb76f0f3 100644 --- a/postgres/src/client.rs +++ b/postgres/src/client.rs @@ -443,6 +443,33 @@ impl Client { Ok(Transaction::new(&mut self.runtime, transaction)) } + /// Returns a builder for a transaction with custom settings. + /// + /// Unlike the `transaction` method, the builder can be used to control the transaction's isolation level and other + /// attributes. + /// + /// # Examples + /// + /// ```no_run + /// use postgres::{Client, IsolationLevel, NoTls}; + /// + /// # fn main() -> Result<(), postgres::Error> { + /// let mut client = Client::connect("host=localhost user=postgres", NoTls)?; + /// + /// let mut transaction = client.build_transaction() + /// .isolation_level(IsolationLevel::RepeatableRead) + /// .start()?; + /// transaction.execute("UPDATE foo SET bar = 10", &[])?; + /// // ... + /// + /// transaction.commit()?; + /// # Ok(()) + /// # } + /// ``` + pub fn build_transaction(&mut self) -> TransactionBuilder<'_> { + TransactionBuilder::new(&mut self.runtime, self.client.build_transaction()) + } + /// Constructs a cancellation token that can later be used to request /// cancellation of a query running on this connection. /// @@ -483,33 +510,6 @@ impl Client { CancelToken::new(self.client.cancel_token()) } - /// Returns a builder for a transaction with custom settings. - /// - /// Unlike the `transaction` method, the builder can be used to control the transaction's isolation level and other - /// attributes. - /// - /// # Examples - /// - /// ```no_run - /// use postgres::{Client, IsolationLevel, NoTls}; - /// - /// # fn main() -> Result<(), postgres::Error> { - /// let mut client = Client::connect("host=localhost user=postgres", NoTls)?; - /// - /// let mut transaction = client.build_transaction() - /// .isolation_level(IsolationLevel::RepeatableRead) - /// .start()?; - /// transaction.execute("UPDATE foo SET bar = 10", &[])?; - /// // ... - /// - /// transaction.commit()?; - /// # Ok(()) - /// # } - /// ``` - pub fn build_transaction(&mut self) -> TransactionBuilder<'_> { - TransactionBuilder::new(&mut self.runtime, self.client.build_transaction()) - } - /// Determines if the client's connection has already closed. /// /// If this returns `true`, the client is no longer usable. diff --git a/tokio-postgres/src/client.rs b/tokio-postgres/src/client.rs index 84ebfcbb..4cd0b31c 100644 --- a/tokio-postgres/src/client.rs +++ b/tokio-postgres/src/client.rs @@ -447,6 +447,14 @@ impl Client { Ok(Transaction::new(self)) } + /// Returns a builder for a transaction with custom settings. + /// + /// Unlike the `transaction` method, the builder can be used to control the transaction's isolation level and other + /// attributes. + pub fn build_transaction(&mut self) -> TransactionBuilder<'_> { + TransactionBuilder::new(self) + } + /// Constructs a cancellation token that can later be used to request /// cancellation of a query running on the connection associated with /// this client. @@ -460,14 +468,6 @@ impl Client { } } - /// Returns a builder for a transaction with custom settings. - /// - /// Unlike the `transaction` method, the builder can be used to control the transaction's isolation level and other - /// attributes. - pub fn build_transaction(&mut self) -> TransactionBuilder<'_> { - TransactionBuilder::new(self) - } - /// Attempts to cancel an in-progress query. /// /// The server provides no information about whether a cancellation attempt was successful or not. An error will