Use a single source of truth for supported Dialects to prevent drift#1
Open
globalchubby wants to merge 4 commits intofix/917from
Open
Use a single source of truth for supported Dialects to prevent drift#1globalchubby wants to merge 4 commits intofix/917from
globalchubby wants to merge 4 commits intofix/917from
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR adds
dialects.registryto prevent drift betweendatabase.NewStore'slookupmap anddatabase.ParseDialect. This registry lives ininternal/dialects/registry.go. The downside is that we're now maintaining the canonical list ofDialectvalues in three packages (goose,database, anddialects) instead of the current two, but I thought it resulted in better encapsulation to keep the registry as an internal module instead of pollutingdatabase.Because we have to support both
stringandDialect, unless we build an additional index, one ofdialects.Parseordialects.Querierwill have a suboptimal iteration over the registry. I felt that creating an additional index was overkill, so I chose to pay the penalty inParseDialect.I'm guessing clarity trumps performance in these code paths though, and if it's clearer to have a registry with
stringalias keys instead ofDialectkeys, I'm open to implementing this PR that way as well.This PR also introduces a slight improvement:
dialect.Querierinstances are created per dialect indatabase.NewStore, instead of eagerly all-at-once.