From 8018634186ed29dd6525d6f4765b27acc6125e74 Mon Sep 17 00:00:00 2001 From: Ravi Suhag Date: Fri, 30 Jun 2023 21:19:48 -0500 Subject: [PATCH] feat(db): add function to fetch connection url --- db/db.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/db/db.go b/db/db.go index f0799a9..79b1446 100644 --- a/db/db.go +++ b/db/db.go @@ -13,6 +13,7 @@ import ( type Client struct { *sqlx.DB queryTimeOut time.Duration + cfg Config } // NewClient creates a new sqlx database client @@ -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) { @@ -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()