From eab66e323fe50170e5d53710b6529781ffd66e25 Mon Sep 17 00:00:00 2001
From: Garet Halliday <ghalliday@gfxlabs.io>
Date: Fri, 30 Sep 2022 13:08:38 -0500
Subject: [PATCH] add name field

---
 lib/gat/admin/admin.go       | 4 ++++
 lib/gat/database/database.go | 8 +++++++-
 lib/gat/gatling/gatling.go   | 2 +-
 lib/gat/interfaces.go        | 1 +
 4 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/lib/gat/admin/admin.go b/lib/gat/admin/admin.go
index 32823d98..c921dcc8 100644
--- a/lib/gat/admin/admin.go
+++ b/lib/gat/admin/admin.go
@@ -535,6 +535,10 @@ func (p *Database) GetRouter() gat.QueryRouter {
 	return nil
 }
 
+func (p *Database) GetName() string {
+	return "pggat"
+}
+
 func (p *Database) WithUser(name string) gat.Pool {
 	conf := p.gat.GetConfig()
 	if name != conf.General.AdminUsername {
diff --git a/lib/gat/database/database.go b/lib/gat/database/database.go
index ec044f0c..a54060b6 100644
--- a/lib/gat/database/database.go
+++ b/lib/gat/database/database.go
@@ -14,6 +14,7 @@ type Database struct {
 	c         *config.Pool
 	users     map[string]config.User
 	connPools map[string]gat.Pool
+	name      string
 
 	stats *gat.PoolStats
 
@@ -24,11 +25,12 @@ type Database struct {
 	mu sync.RWMutex
 }
 
-func New(dialer gat.Dialer, conf *config.Pool) *Database {
+func New(dialer gat.Dialer, name string, conf *config.Pool) *Database {
 	pool := &Database{
 		connPools: make(map[string]gat.Pool),
 		stats:     gat.NewPoolStats(),
 		router:    query_router.DefaultRouter(conf),
+		name:      name,
 
 		dialer: dialer,
 	}
@@ -74,6 +76,10 @@ func (p *Database) GetRouter() gat.QueryRouter {
 	return p.router
 }
 
+func (p *Database) GetName() string {
+	return p.name
+}
+
 func (p *Database) WithUser(name string) gat.Pool {
 	p.mu.RLock()
 	defer p.mu.RUnlock()
diff --git a/lib/gat/gatling/gatling.go b/lib/gat/gatling/gatling.go
index 42988948..746614d0 100644
--- a/lib/gat/gatling/gatling.go
+++ b/lib/gat/gatling/gatling.go
@@ -141,7 +141,7 @@ func (g *Gatling) ensurePools(c *config.Global) error {
 		if existing, ok := g.pools[name]; ok {
 			existing.EnsureConfig(p)
 		} else {
-			g.pools[name] = database.New(server.Dial, p)
+			g.pools[name] = database.New(server.Dial, name, p)
 		}
 	}
 	return nil
diff --git a/lib/gat/interfaces.go b/lib/gat/interfaces.go
index fc4ab08e..6c13c30c 100644
--- a/lib/gat/interfaces.go
+++ b/lib/gat/interfaces.go
@@ -63,6 +63,7 @@ type Gat interface {
 type Database interface {
 	GetUser(name string) *config.User
 	GetRouter() QueryRouter
+	GetName() string
 
 	WithUser(name string) Pool
 	GetPools() []Pool
-- 
GitLab