-
-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support transaction #22
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- examples - txn - update accordingly to use `transaction` fn
Something like this works. diff --git a/postgres/src/lib.rs b/postgres/src/lib.rs
index 87c38ce..47bd6a7 100644
--- a/postgres/src/lib.rs
+++ b/postgres/src/lib.rs
@@ -90,16 +90,20 @@ where
}
/// Run asynchronous into a Transaction
-pub fn transaction<R, Fut, F>(mut connection: tokio_postgres::Client, f: F) -> impl Future<Item=(R, tokio_postgres::Client), Error=(tokio_postgres::Error, tokio_postgres::Client)>
+pub fn transaction<R, E, Fut, F>(mut connection: tokio_postgres::Client, f: F) -> impl Future<Item=(R, tokio_postgres::Client), Error=(E, tokio_postgres::Client)>
where
F: FnOnce(tokio_postgres::Client) -> Fut,
- Fut: Future<Item=(R, tokio_postgres::Client), Error=(tokio_postgres::Error, tokio_postgres::Client)>,
+ E: From<tokio_postgres::Error>,
+ Fut: Future<Item=(R, tokio_postgres::Client), Error=(E, tokio_postgres::Client)>,
{
connection.simple_query("BEGIN")
.for_each(|_| Ok(()))
.then(|r| match r {
Ok(_) => Ok(connection),
- Err(e) => Err((e, connection)),
+ Err(e) => {
+ let error: E = e.into();
+ Err((error, connection))
+ },
})
.and_then(|connection| f(connection))
.and_then(|(result, mut connection)| {
@@ -107,11 +111,11 @@ pub fn transaction<R, Fut, F>(mut connection: tokio_postgres::Client, f: F) -> i
.for_each(|_| Ok(()))
.then(|r| match r {
Ok(_) => Ok((result, connection)),
- Err(e) => Err((e, connection))
+ Err(e) => Err((e.into(), connection))
})
})
.or_else(|(e, mut connection)| {
connection.simple_query("ROLLBACK").for_each(|_| Ok(()))
- .then(|_| Err((e, connection)))
+ .then(|_| Err((e.into(), connection)))
})
-}
\ No newline at end of file
+} |
@khuey thanks for the help, from here on, what's next? |
@elpiel are you still interested in finishing this? |
Yes, I am. I would love to continue on this once the #45 is merged. |
Going to close this for lack of progress. Feel free to reopen (or open a new one) if someone wants to work on this. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently the
fn transaction()
was created for the postgres implementation as per #20 (comment) .We can implement the same thing for Redis and add a transaction fn in
bb8
that will call the specific connectiontransaction()
fn I guess?Resolves #20
@khuey I couldn't get the
E: From<tokio_postgres::Error>
working sadly.