Refactor: Support for SQL Server (WIP for discussion) #1605
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.
Previously:
Problem
Right now, SQL Server has bespoke SQL required to do bearing calculations.
Other datastores have a similar problem, ie SQLite, depending on what is available.
At some point, Geocoder::Sql was split out to try to make managing this a little bit easier, but it accidentally lead to the situation where:
Geocoder::Store::Activerecord
had a number of methods and conditionals to decide which of the other class' methods to callGeocoder::Sql
doesn't know what database it is connected to, so can't generate correct SQL for every situationRecommended solution
Ultimately, I think the responsibility for which datastore am I connected to does live in
Geocoder::Store::Activerecord
; but specific backends should be available for standard sql, vs sqlite, vs postgres, vs sql server.This might seem like it violates DRY, but ultimately it would help acheive a single-responsibility-principle.
Transitioning and backwards compatibility
What I have done in this PR is really a step 1; where the standalone methods are marked deprecated.
This allows a future major version to remove them.
Additionally, at least for now I have shifted the sql generating concerns back into Geocoder::Store::Activerecord. This is because there is an implicit coupling between "which SQL should I generate" and "what am I connected to?". It introduces an extra layer of conditionals in the sql generation temporarily.
A subsequent PR should (with a major version to indicate the BC break)
What next?
If this kind of plan seems acceptable, I'm happy to help implement, test, refactor, etc.
If the feeling is still it doesn't fit; may fork (would want 1-2 other maintainers).