From 59e3ada20c7a529cfdf31d5e327b3a1b5b83f7cf Mon Sep 17 00:00:00 2001 From: aeneasr <3372410+aeneasr@users.noreply.github.com> Date: Tue, 24 May 2022 18:00:09 +0200 Subject: [PATCH 1/2] feat: expose normalizeSynonyms --- connection_details.go | 4 ++-- connection_instrumented.go | 2 +- match.go | 2 +- pop.go | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/connection_details.go b/connection_details.go index 50c2fe4b..cf83df6d 100644 --- a/connection_details.go +++ b/connection_details.go @@ -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 = NormalizeDialectSynonyms(dialect) } else { return errors.New("no dialect provided, and could not guess it from URL") } @@ -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 = NormalizeDialectSynonyms(cd.Dialect) if cd.Options == nil { // for safety cd.Options = make(map[string]string) diff --git a/connection_instrumented.go b/connection_instrumented.go index 435b50db..a5d7b2ba 100644 --- a/connection_instrumented.go +++ b/connection_instrumented.go @@ -39,7 +39,7 @@ func instrumentDriver(deets *ConnectionDetails, defaultDriverName string) (drive var dr driver.Driver var newDriverName string - switch normalizeSynonyms(driverName) { + switch NormalizeDialectSynonyms(driverName) { case nameCockroach: fallthrough case namePostgreSQL: diff --git a/match.go b/match.go index 045dfe87..6d24ab68 100644 --- a/match.go +++ b/match.go @@ -26,7 +26,7 @@ func ParseMigrationFilename(filename string) (*Match, error) { if m[3] == "" { dbType = "all" } else { - dbType = normalizeSynonyms(m[3][1:]) + dbType = NormalizeDialectSynonyms(m[3][1:]) if !DialectSupported(dbType) { return nil, fmt.Errorf("unsupported dialect %s", dbType) } diff --git a/pop.go b/pop.go index 7d0445ee..ae164d70 100644 --- a/pop.go +++ b/pop.go @@ -56,7 +56,7 @@ func DialectSupported(d string) bool { return false } -func normalizeSynonyms(dialect string) string { +func NormalizeDialectSynonyms(dialect string) string { d := strings.ToLower(dialect) if syn, ok := dialectSynonyms[d]; ok { d = syn From 2a0dd4a4ebaac409e355256184a8533ddc3fb790 Mon Sep 17 00:00:00 2001 From: Yonghwan SO Date: Sat, 4 Jun 2022 15:22:33 +0900 Subject: [PATCH 2/2] rename NormalizeDialectSynonyms to CanonicalDialect --- connection_details.go | 4 ++-- connection_instrumented.go | 2 +- match.go | 2 +- pop.go | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/connection_details.go b/connection_details.go index cf83df6d..35c1b761 100644 --- a/connection_details.go +++ b/connection_details.go @@ -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 = NormalizeDialectSynonyms(dialect) + cd.Dialect = CanonicalDialect(dialect) } else { return errors.New("no dialect provided, and could not guess it from URL") } @@ -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 = NormalizeDialectSynonyms(cd.Dialect) + cd.Dialect = CanonicalDialect(cd.Dialect) if cd.Options == nil { // for safety cd.Options = make(map[string]string) diff --git a/connection_instrumented.go b/connection_instrumented.go index a5d7b2ba..e38eee7b 100644 --- a/connection_instrumented.go +++ b/connection_instrumented.go @@ -39,7 +39,7 @@ func instrumentDriver(deets *ConnectionDetails, defaultDriverName string) (drive var dr driver.Driver var newDriverName string - switch NormalizeDialectSynonyms(driverName) { + switch CanonicalDialect(driverName) { case nameCockroach: fallthrough case namePostgreSQL: diff --git a/match.go b/match.go index 6d24ab68..37a45940 100644 --- a/match.go +++ b/match.go @@ -26,7 +26,7 @@ func ParseMigrationFilename(filename string) (*Match, error) { if m[3] == "" { dbType = "all" } else { - dbType = NormalizeDialectSynonyms(m[3][1:]) + dbType = CanonicalDialect(m[3][1:]) if !DialectSupported(dbType) { return nil, fmt.Errorf("unsupported dialect %s", dbType) } diff --git a/pop.go b/pop.go index ae164d70..97d025a7 100644 --- a/pop.go +++ b/pop.go @@ -56,8 +56,8 @@ func DialectSupported(d string) bool { return false } -func NormalizeDialectSynonyms(dialect string) string { - d := strings.ToLower(dialect) +func CanonicalDialect(synonym string) string { + d := strings.ToLower(synonym) if syn, ok := dialectSynonyms[d]; ok { d = syn }