Skip to content

Commit

Permalink
feat(client): add a call to connection.BuildConnectionFromOpts to bui…
Browse files Browse the repository at this point in the history
…ld the conn string given the options
  • Loading branch information
danvergara committed Apr 22, 2021
1 parent ab04424 commit 834a34e
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
_ "github.com/lib/pq"

"github.com/danvergara/dblab/pkg/command"
"github.com/danvergara/dblab/pkg/connection"
"github.com/jmoiron/sqlx"
)

Expand All @@ -17,7 +18,12 @@ type Client struct {

// New return an instance of the client.
func New(opts command.Options) (*Client, error) {
db, err := sqlx.Open(opts.Driver, opts.URL)
conn, err := connection.BuildConnectionFromOpts(opts)
if err != nil {
return nil, err
}

db, err := sqlx.Open(opts.Driver, conn)
if err != nil {
return nil, err
}
Expand All @@ -28,3 +34,8 @@ func New(opts command.Options) (*Client, error) {

return &c, nil
}

// DB Return the db attribute
func (c *Client) DB() *sqlx.DB {
return c.db
}

0 comments on commit 834a34e

Please sign in to comment.