Skip to content

Commit

Permalink
feat(db): add function to fetch connection url
Browse files Browse the repository at this point in the history
  • Loading branch information
ravisuhag committed Jul 1, 2023
1 parent 5201185 commit 8018634
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
type Client struct {
*sqlx.DB
queryTimeOut time.Duration
cfg Config
}

// NewClient creates a new sqlx database client
Expand All @@ -26,7 +27,7 @@ func New(cfg Config) (*Client, error) {
db.SetMaxOpenConns(cfg.MaxOpenConns)
db.SetConnMaxLifetime(cfg.ConnMaxLifeTime)

return &Client{DB: db, queryTimeOut: cfg.MaxQueryTimeout}, err
return &Client{DB: db, queryTimeOut: cfg.MaxQueryTimeout, cfg: cfg}, err
}

func (c Client) WithTimeout(ctx context.Context, op func(ctx context.Context) error) (err error) {
Expand Down Expand Up @@ -67,6 +68,11 @@ func (c Client) WithTxn(ctx context.Context, txnOptions sql.TxOptions, txFunc fu
return err
}

// ConnectionURL fetch the database connection url
func (c *Client) ConnectionURL() string {
return c.cfg.URL
}

// Close closes the database connection
func (c *Client) Close() error {
return c.DB.Close()
Expand Down

0 comments on commit 8018634

Please sign in to comment.