Skip to content

Commit d58b181

Browse files
committed
Fix up new transaction API
1 parent a9b01b4 commit d58b181

2 files changed

Lines changed: 10 additions & 27 deletions

File tree

tokio-postgres/src/lib.rs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -101,22 +101,7 @@ impl Client {
101101
CopyOut(self.0.copy_out(&statement.0, params))
102102
}
103103

104-
pub fn transaction<T>(&mut self, future: T) -> Transaction<T>
105-
where
106-
T: Future,
107-
// FIXME error type?
108-
T::Error: From<Error>,
109-
{
110-
self.transaction_builder().build(future)
111-
}
112-
113-
/// Creates a TransactionBuilder, which can later be used to create
114-
/// a Transaction around a future.
115-
///
116-
/// Use this when Client is moved into the future being built.
117-
/// For example, when executing multiple statements that depend
118-
/// on the previous statement's result.
119-
pub fn transaction_builder(&self) -> TransactionBuilder {
104+
pub fn transaction(&mut self) -> TransactionBuilder {
120105
TransactionBuilder(self.0.clone())
121106
}
122107

tokio-postgres/tests/test.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ fn transaction_commit() {
537537
)).unwrap();
538538

539539
let f = client.batch_execute("INSERT INTO foo (name) VALUES ('steven')");
540-
runtime.block_on(client.transaction(f)).unwrap();
540+
runtime.block_on(client.transaction().build(f)).unwrap();
541541

542542
let rows = runtime
543543
.block_on(
@@ -573,7 +573,7 @@ fn transaction_abort() {
573573
.batch_execute("INSERT INTO foo (name) VALUES ('steven')")
574574
.map_err(|e| Box::new(e) as Box<Error>)
575575
.and_then(|_| Err::<(), _>(Box::<Error>::from("")));
576-
runtime.block_on(client.transaction(f)).unwrap_err();
576+
runtime.block_on(client.transaction().build(f)).unwrap_err();
577577

578578
let rows = runtime
579579
.block_on(
@@ -700,21 +700,19 @@ fn transaction_builder_around_moved_client() {
700700
let mut runtime = Runtime::new().unwrap();
701701

702702
let (mut client, connection) = runtime
703-
.block_on(tokio_postgres::connect(
704-
"postgres://postgres@localhost:5433".parse().unwrap(),
705-
TlsMode::None,
706-
)).unwrap();
703+
.block_on(connect(tokio_postgres::Builder::new().user("postgres")))
704+
.unwrap();
707705
let connection = connection.map_err(|e| panic!("{}", e));
708706
runtime.handle().spawn(connection).unwrap();
709707

710-
let transaction_builder = client.transaction_builder();
708+
let transaction_builder = client.transaction();
711709
let work = future::lazy(move || {
712-
let execute =
713-
client.batch_execute(
714-
"CREATE TEMPORARY TABLE transaction_foo (
710+
let execute = client.batch_execute(
711+
"CREATE TEMPORARY TABLE transaction_foo (
715712
id SERIAL,
716713
name TEXT
717-
)");
714+
)",
715+
);
718716

719717
execute.and_then(move |_| {
720718
client

0 commit comments

Comments
 (0)