Reuse existing db connection (if any)

This commit is contained in:
ditatompel 2024-06-10 02:47:44 +07:00
parent 70372e58ab
commit 5f5ebd81a9
No known key found for this signature in database
GPG key ID: 31D3D06D77950979

View file

@ -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,