Refactor portability statement into a functional composition #4039
+812
−172
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.
The current implementation of the portability statement contains quite a lot of code repetition, especially introduced at #4019. The reason is that there's no clear separation of concerns of data fetching and data transformation which is aggravated by the number of possible configurations.
In order to make the code more extensible, the statement is split into a wrapper that fetches the data from the underlying statement and a converter that converts the data. Unlike the current design, the converter is created once per connection and is then reused for all fetches.
The other benefit that the separation of concerns gives is that the converter can be fully unit-tested w/o the need to mock the underlying statement or set up data fixtures.