Skip to content
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: expose normalizeSynonyms #721

Merged
merged 2 commits into from Jun 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions connection_details.go
Expand Up @@ -78,7 +78,7 @@ func (cd *ConnectionDetails) withURL() error {
if dialectX.MatchString(ul) {
// Guess the dialect from the scheme
dialect := ul[:strings.Index(ul, ":")]
cd.Dialect = normalizeSynonyms(dialect)
cd.Dialect = CanonicalDialect(dialect)
} else {
return errors.New("no dialect provided, and could not guess it from URL")
}
Expand Down Expand Up @@ -125,7 +125,7 @@ func (cd *ConnectionDetails) withURL() error {
// Finalize cleans up the connection details by normalizing names,
// filling in default values, etc...
func (cd *ConnectionDetails) Finalize() error {
cd.Dialect = normalizeSynonyms(cd.Dialect)
cd.Dialect = CanonicalDialect(cd.Dialect)

if cd.Options == nil { // for safety
cd.Options = make(map[string]string)
Expand Down
2 changes: 1 addition & 1 deletion connection_instrumented.go
Expand Up @@ -39,7 +39,7 @@ func instrumentDriver(deets *ConnectionDetails, defaultDriverName string) (drive

var dr driver.Driver
var newDriverName string
switch normalizeSynonyms(driverName) {
switch CanonicalDialect(driverName) {
case nameCockroach:
fallthrough
case namePostgreSQL:
Expand Down
2 changes: 1 addition & 1 deletion match.go
Expand Up @@ -26,7 +26,7 @@ func ParseMigrationFilename(filename string) (*Match, error) {
if m[3] == "" {
dbType = "all"
} else {
dbType = normalizeSynonyms(m[3][1:])
dbType = CanonicalDialect(m[3][1:])
if !DialectSupported(dbType) {
return nil, fmt.Errorf("unsupported dialect %s", dbType)
}
Expand Down
4 changes: 2 additions & 2 deletions pop.go
Expand Up @@ -56,8 +56,8 @@ func DialectSupported(d string) bool {
return false
}

func normalizeSynonyms(dialect string) string {
d := strings.ToLower(dialect)
func CanonicalDialect(synonym string) string {
d := strings.ToLower(synonym)
if syn, ok := dialectSynonyms[d]; ok {
d = syn
}
Expand Down