Skip to content

Commit

Permalink
Fix mariadb driver issue (#543)
Browse files Browse the repository at this point in the history
* Fix mariadb driver issue

* Fix tests

* Fix cockroach driver
  • Loading branch information
stanislas-m authored Apr 25, 2020
1 parent 72b8606 commit 6842d77
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 4 deletions.
2 changes: 1 addition & 1 deletion connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (c *Connection) Open() error {
return errors.New("invalid connection instance")
}
details := c.Dialect.Details()
driver := details.Dialect
driver := c.Dialect.DefaultDriver()
if details.Driver != "" {
driver = details.Driver
}
Expand Down
4 changes: 2 additions & 2 deletions connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func Test_Connection_Open_NoDialect(t *testing.T) {
r.Error(err)
}

func Test_Connection_Open_BadDialect(t *testing.T) {
func Test_Connection_Open_BadDriver(t *testing.T) {
r := require.New(t)

cd := &ConnectionDetails{
Expand All @@ -48,7 +48,7 @@ func Test_Connection_Open_BadDialect(t *testing.T) {
c, err := NewConnection(cd)
r.NoError(err)

cd.Dialect = "unknown"
cd.Driver = "unknown"
err = c.Open()
r.Error(err)
}
1 change: 1 addition & 0 deletions dialect.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type dialect interface {
fizzable
quotable
Name() string
DefaultDriver() string
URL() string
MigrationURL() string
Details() *ConnectionDetails
Expand Down
5 changes: 4 additions & 1 deletion dialect_cockroach.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"strings"
"sync"

_ "github.com/cockroachdb/cockroach-go/crdb" // Load CockroachdbQL/postgres Go driver which also loads github.com/lib/pq
"github.com/gobuffalo/fizz"
"github.com/gobuffalo/fizz/translators"
"github.com/gobuffalo/pop/v5/columns"
Expand Down Expand Up @@ -57,6 +56,10 @@ func (p *cockroach) Name() string {
return nameCockroach
}

func (p *cockroach) DefaultDriver() string {
return namePostgreSQL
}

func (p *cockroach) Details() *ConnectionDetails {
return p.ConnectionDetails
}
Expand Down
4 changes: 4 additions & 0 deletions dialect_mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ func (m *mysql) Name() string {
return nameMySQL
}

func (m *mysql) DefaultDriver() string {
return nameMySQL
}

func (mysql) Quote(key string) string {
return fmt.Sprintf("`%s`", key)
}
Expand Down
4 changes: 4 additions & 0 deletions dialect_postgresql.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ func (p *postgresql) Name() string {
return namePostgreSQL
}

func (p *postgresql) DefaultDriver() string {
return namePostgreSQL
}

func (p *postgresql) Details() *ConnectionDetails {
return p.ConnectionDetails
}
Expand Down
4 changes: 4 additions & 0 deletions dialect_sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ func (m *sqlite) Name() string {
return nameSQLite3
}

func (m *sqlite) DefaultDriver() string {
return nameSQLite3
}

func (m *sqlite) Details() *ConnectionDetails {
return m.ConnectionDetails
}
Expand Down
3 changes: 3 additions & 0 deletions finders_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ func Test_Find_Eager_Has_Many(t *testing.T) {
}

func Test_All_Eager_Preload_Mode(t *testing.T) {
if PDB == nil {
t.Skip("skipping integration tests")
}
transaction(func(tx *Connection) {
r := require.New(t)

Expand Down
12 changes: 12 additions & 0 deletions preload_associations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (
)

func Test_New_Implementation_For_Nplus1(t *testing.T) {
if PDB == nil {
t.Skip("skipping integration tests")
}
transaction(func(tx *Connection) {
a := require.New(t)
for _, name := range []string{"Mark", "Joe", "Jane"} {
Expand Down Expand Up @@ -54,6 +57,9 @@ func Test_New_Implementation_For_Nplus1(t *testing.T) {
}

func Test_New_Implementation_For_Nplus1_With_UUID(t *testing.T) {
if PDB == nil {
t.Skip("skipping integration tests")
}
transaction(func(tx *Connection) {
a := require.New(t)

Expand Down Expand Up @@ -96,6 +102,9 @@ func Test_New_Implementation_For_Nplus1_With_UUID(t *testing.T) {
}

func Test_New_Implementation_For_Nplus1_Single(t *testing.T) {
if PDB == nil {
t.Skip("skipping integration tests")
}
transaction(func(tx *Connection) {
a := require.New(t)
for _, name := range []string{"Mark", "Joe", "Jane"} {
Expand Down Expand Up @@ -135,6 +144,9 @@ func Test_New_Implementation_For_Nplus1_Single(t *testing.T) {
}

func Test_New_Implementation_For_Nplus1_Nested(t *testing.T) {
if PDB == nil {
t.Skip("skipping integration tests")
}
transaction(func(tx *Connection) {
a := require.New(t)
var song Song
Expand Down

0 comments on commit 6842d77

Please sign in to comment.