From 5f5ebd81a9ad936447ea985b03a337210ca63128 Mon Sep 17 00:00:00 2001 From: ditatompel Date: Mon, 10 Jun 2024 02:47:44 +0700 Subject: [PATCH] Reuse existing db connection (if any) --- internal/database/mysql.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/database/mysql.go b/internal/database/mysql.go index 298f0ff..03dccd4 100644 --- a/internal/database/mysql.go +++ b/internal/database/mysql.go @@ -16,6 +16,10 @@ var defaultDB = &DB{} // connect sets the db client of database using configuration func (db *DB) connect(cfg *config.DB) (err error) { + if defaultDB.DB != nil { + return nil // reuse existing connection if available + } + dbURI := fmt.Sprintf("%s:%s@(%s:%d)/%s", cfg.User, cfg.Password,