Skip to content
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

Refactor duplicated transaction management code #618

Merged
merged 1 commit into from
Feb 4, 2017

Conversation

sgrif
Copy link
Member

@sgrif sgrif commented Feb 4, 2017

The code for transactions is duplicated between SQLite and PostgreSQL.
MySQL would have also used identical code. However, the SQL being
executed is not universal across all backends. Oracle appears to use the
same SQL, but SQL Server has its own special syntax for this. As such,
I'm not comfortable promoting this to a default impl on the trait.
Instead I've moved the code out into a shared trait/struct, and operate
on that instead.

I had wanted to make TransactionManager be generic over the backend,
not the connection itself, since constraints for it will always be about
the backend, but I ran into
rust-lang/rust#39532 when attempting to do so.

The code for transactions is duplicated between SQLite and PostgreSQL.
MySQL would have also used identical code. However, the SQL being
executed is not universal across all backends. Oracle appears to use the
same SQL, but SQL Server has its own special syntax for this. As such,
I'm not comfortable promoting this to a default impl on the trait.
Instead I've moved the code out into a shared trait/struct, and operate
on that instead.

I had wanted to make `TransactionManager` be generic over the backend,
not the connection itself, since constraints for it will always be about
the backend, but I ran into
rust-lang/rust#39532 when attempting to do so.
@sgrif sgrif requested a review from killercup February 4, 2017 13:13
Copy link
Member

@killercup killercup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice refactoring.

/// interface with this trait unless you are implementing a new connection
/// adapter. You should use [`Connection::transaction`][transaction],
/// [`Connection::test_transaction`][test_transaction], or
/// [`Connection::begin_test_transaction`][begin_test_transaction] instead.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You know I link links. Can you add some? Let's say, three?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But you just said that you would link links. ;)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, what I meant to say was that I link likes! :D

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to do it as a separate commit. I need to rebase something off this branch to open a PR

@sgrif sgrif merged commit c2db329 into master Feb 4, 2017
@sgrif sgrif deleted the sg-refactor-transactions branch February 4, 2017 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants