-
Notifications
You must be signed in to change notification settings - Fork 4
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
fix: move runInTransaction to ViewerContext #108
Conversation
Codecov Report
@@ Coverage Diff @@
## master #108 +/- ##
=======================================
Coverage 94.95% 94.96%
=======================================
Files 66 66
Lines 1624 1627 +3
Branches 195 177 -18
=======================================
+ Hits 1542 1545 +3
Misses 80 80
Partials 2 2
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
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.
nice. ✨
I would be curious to know what other flavors will be added. For example if MySQL is added then things would be similar enough for transactions that a runInSQLTransactionAsync
method seems like the cleaner abstraction.
We'd need one method per flavor just in case an application uses multiple flavors. This flavor concept as a whole though probably needs to be removed and just replaced with strings so that client applications can have as many "flavors" as they want and configure them however they like. |
Since the number of database flavors will likely stay small, having hardcoded methods seems good so that we don't need to pass the same parameter in everywhere. It also might help with type hints a bit if the Postgres query context were to be different than a MySQL query context. Longer-term, if we have multiple flavors, I think we will want to automatically detect what flavors are used and just have a generic "runInTransactionAsync" method that creates the correct query contexts on the fly as needed, or at least warn if you started a Postgres transaction but tried to access MySQL. There might be cases where we need to let developers opt out (e.g. they want a PG transaction but not a MySQL one) but those cases seem rare. |
@@ -226,6 +226,13 @@ export default class EntityCompanionProvider { | |||
}); | |||
} | |||
|
|||
getQueryContextProviderForDatabaseAdaptorFlavor( |
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.
Might want to make getTableDataCoordinatorForEntity
call this so that the behavior between the two methods stays in sync.
Why
This has been suggested by @jkhales and @ide a few times as a better pattern. At its core this does the same thing as the previous implementation, it just removes the unnecessary association with concrete entity types.
How
Move the methods to
ViewerContext
. Note that this will most likely be used in methods inViewerContext
subclasses in the following manner:so that callsites don't need to specify the
DatabaseAdapterFlavor
.Questions for Reviewers
Do you think it's worth added these
DatabaseAdapterFlavor
-hardcoded methods toViewerContext
? Since theDatabaseAdapterFlavor
is hardcoded in this package, it can be done cleanly. The upside is that consumers don't need to specify them. The downside is that the number of methods would grow if we add moreDatabaseAdapterFlavor
s.Test Plan
Run all tests.