-
-
Notifications
You must be signed in to change notification settings - Fork 79
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
feat(transaction): Adding withTransaction #519
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added some more comments.
let _ = try await client.withTransaction(logger: logger) { transaction in | ||
try await transaction.query( | ||
""" | ||
INSERT INTO "\(unescaped: tableName)" (uuid) VALUES (\(iterations)); | ||
""", | ||
logger: logger | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't check the error here at all. There is also nothing here to rollback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests have been updated. I apologize about skipping this part.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #519 +/- ##
==========================================
- Coverage 61.75% 61.68% -0.07%
==========================================
Files 125 125
Lines 10089 10099 +10
==========================================
Hits 6230 6230
- Misses 3859 3869 +10
|
/// - Parameter closure: A closure that uses the passed `PostgresConnection`. The closure **must not** capture | ||
/// the provided `PostgresConnection`. | ||
/// - Returns: The closure's return value. | ||
public func withTransaction<Result>(_ process: (PostgresConnection) async throws -> Result) async throws -> Result { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should capture calling file and line here. Then we could attach that info to the error that is thrown. We would wrap the thrown error in a PostgresTransactionError
. We could also attach the Rollback error, if that happens. cc @gwynne WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me, yeah.
Co-authored-by: Fabian Fett <fabianfett@apple.com>
First pass at feature #512
What's the best way to go about writing unit test for the withTransaction func?