Skip to content

Commit

Permalink
Add optional attribute 'driver' to config (#404)
Browse files Browse the repository at this point in the history
This will help to use custom mock drivers or replacements.
Full credits to @0nedark whose PR branch was deleted before the review.
  • Loading branch information
stanislas-m authored Jun 26, 2019
1 parent 4326f96 commit b6770e4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 6 additions & 1 deletion connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,12 @@ func (c *Connection) Open() error {
return errors.New("invalid connection instance")
}
details := c.Dialect.Details()
db, err := sqlx.Open(details.Dialect, c.Dialect.URL())
driver := details.Dialect
if details.Driver != "" {
driver = details.Driver
}

db, err := sqlx.Open(driver, c.Dialect.URL())
if err != nil {
return errors.Wrap(err, "could not open database connection")
}
Expand Down
4 changes: 3 additions & 1 deletion connection_details.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ import (

// ConnectionDetails stores the data needed to connect to a datasource
type ConnectionDetails struct {
// Example: "postgres" or "sqlite3" or "mysql"
// Dialect is the pop dialect to use. Example: "postgres" or "sqlite3" or "mysql"
Dialect string
// Driver specifies the database driver to use (optional)
Driver string
// The name of your database. Example: "foo_development"
Database string
// The host of your database. Example: "127.0.0.1"
Expand Down

0 comments on commit b6770e4

Please sign in to comment.