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

Transaction 3 #222

Merged
merged 24 commits into from
Oct 12, 2021
Merged

Transaction 3 #222

merged 24 commits into from
Oct 12, 2021

Conversation

tyt2y3
Copy link
Member

@tyt2y3 tyt2y3 commented Oct 4, 2021

Continue #199 on #142

Tasks

  • MockConnection support
  • Rework Rocket support
  • Test cases

TODO: nested transaction
@tyt2y3
Copy link
Member Author

tyt2y3 commented Oct 8, 2021

@nappa85 have you tried nested transaction, i.e. multiple begin() and mutiple commit() on same connection?

@tyt2y3
Copy link
Member Author

tyt2y3 commented Oct 8, 2021

Was there a reason where TransactionError is a standalone enum instead of being a variant of DbErr?
If not, I'd merge it into DbErr, and use a Box<dyn Error> for simplicity.

@nappa85
Copy link
Contributor

nappa85 commented Oct 8, 2021

Was there a reason where TransactionError is a standalone enum instead of being a variant of DbErr? If not, I'd merge it into DbErr, and use a Box<dyn Error> for simplicity.

I don't like "Boxdyning" things, adds an indirection that is often avoidable.
If I remember correctly, TransactionError was made to wrap the error returned from the closure, but distinct between transaction begin errors and closure errors.

@nappa85
Copy link
Contributor

nappa85 commented Oct 8, 2021

@nappa85 have you tried nested transaction, i.e. multiple begin() and mutiple commit() on same connection?

Not extensively TBH, but should be trivial...
Have you found problems?

@tyt2y3
Copy link
Member Author

tyt2y3 commented Oct 8, 2021

Not extensively TBH, but should be trivial... Have you found problems?

No. Am trying to write some test cases on this. It'd be great if you can share your experience on its behavior, and see if it aligns with my understanding.

@nappa85
Copy link
Contributor

nappa85 commented Oct 8, 2021

Not extensively TBH, but should be trivial... Have you found problems?

No. Am trying to write some test cases on this. It'd be great if you can share your experience on its behavior, and see if it aligns with my understanding.

Under a Transaction there always is a connection, so a nested transaction insists on the same connection of the top level transaction.
In facts there is no difference between running a query on the top level or in a nested level, the result would be the same.
If you think about a SQL console, when you type "START TRANSACTION" the parent transaction is unreachable until you close the child transaction, but you're using the same connection.
This is more or less the same, with the only difference that, if you used begin method, you still have access to the parent transaction object.

This is why I think it's trivial, "START TRANSACTION" is only another query you run on the connection, so if, e.g., query_all works, also begin should work.

@tyt2y3
Copy link
Member Author

tyt2y3 commented Oct 9, 2021

Just to remind myself of the nested transaction implementation of SQLx

https://github.com/launchbadge/sqlx/blob/b6e127561797fe9aababa24ec640275ecb9b42af/sqlx-core/src/transaction.rs#L218

@tyt2y3
Copy link
Member Author

tyt2y3 commented Oct 11, 2021

1a2bd13

I succeeded in implementing and testing the nested transaction in MockInterface.

Looks bright!

@nappa85
Copy link
Contributor

nappa85 commented Oct 11, 2021

How close are we to a stable release?

@tyt2y3
Copy link
Member Author

tyt2y3 commented Oct 11, 2021

I have gone through everything (code, API design & behavior) thoroughly. Everything seems clear now.

I am targeting 0.3 at mid October, probably end of this week!

@billy1624
Copy link
Member

Is this complicated enough? 1280046 @tyt2y3

@tyt2y3
Copy link
Member Author

tyt2y3 commented Oct 12, 2021

Is this complicated enough? 1280046 @tyt2y3

Yes but we need more

@tyt2y3 tyt2y3 merged commit f58d890 into master Oct 12, 2021
@tyt2y3 tyt2y3 deleted the transaction-3 branch October 12, 2021 06:51
@tyt2y3
Copy link
Member Author

tyt2y3 commented Oct 12, 2021

@billy1624 please add more test cases onto master

billy1624 added a commit to SeaQL/seaql.github.io that referenced this pull request Oct 18, 2021
billy1624 added a commit to SeaQL/seaql.github.io that referenced this pull request Oct 18, 2021
tyt2y3 pushed a commit to SeaQL/seaql.github.io that referenced this pull request Oct 19, 2021
arpancodes pushed a commit to arpancodes/sea-orm that referenced this pull request Apr 8, 2022
SeaQL#222)

* Support the use of chrono::DateTime<Utc> using the type alias DateTimeUtc

Add a test to ensure the DateTimeUtc is parsed and converted to SQL equivalent of TIMESTAMP

* Ensure DateTime formatting is consistent

* Implement `From` for Utc

Move FixedOffset to its own `From` implementation

Implement test for Utc

* Return a DateTime<Utc> instead of String

* Return timestamp as a String

* Add example documentation for DateTimeUtc
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.

3 participants