From 1fc6144cc0c1783b837c7da162ca8e9bd1308907 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Muhammed=20Efe=20=C3=87etin?= Date: Thu, 3 Nov 2022 23:36:06 +0300 Subject: [PATCH] add conn --- postgres/v2/README.md | 1 + postgres/v2/postgres.go | 5 +++++ postgres/v2/postgres_test.go | 10 +++++++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/postgres/v2/README.md b/postgres/v2/README.md index 28e6fa4c..fe6b3d2c 100644 --- a/postgres/v2/README.md +++ b/postgres/v2/README.md @@ -17,6 +17,7 @@ func (s *Storage) Set(key string, val []byte, exp time.Duration) error func (s *Storage) Delete(key string) error func (s *Storage) Reset() error func (s *Storage) Close() error +func (s *Storage) Conn() *pgxpool.Pool ``` ### Installation Postgres is tested on the 2 last [Go versions](https://golang.org/dl/) with support for modules. So make sure to initialize one first if you didn't do that yet: diff --git a/postgres/v2/postgres.go b/postgres/v2/postgres.go index e19da885..bd480754 100644 --- a/postgres/v2/postgres.go +++ b/postgres/v2/postgres.go @@ -160,6 +160,11 @@ func (s *Storage) Close() error { return nil } +// Return database client +func (s *Storage) Conn() *pgxpool.Pool { + return s.db +} + // gcTicker starts the gc ticker func (s *Storage) gcTicker() { ticker := time.NewTicker(s.gcInterval) diff --git a/postgres/v2/postgres_test.go b/postgres/v2/postgres_test.go index 5decfa50..ce791da1 100644 --- a/postgres/v2/postgres_test.go +++ b/postgres/v2/postgres_test.go @@ -3,6 +3,7 @@ package v2 import ( "context" "database/sql" + "os" "testing" "time" @@ -10,7 +11,10 @@ import ( ) var testStore = New(Config{ - Reset: true, + Database: os.Getenv("POSTGRES_DATABASE"), + Username: os.Getenv("POSTGRES_USERNAME"), + Password: os.Getenv("POSTGRES_PASSWORD"), + Reset: true, }) func Test_Postgres_Set(t *testing.T) { @@ -167,6 +171,10 @@ func Test_SslRequiredMode(t *testing.T) { }) } +func Test_Postgres_Conn(t *testing.T) { + utils.AssertEqual(t, true, testStore.Conn() != nil) +} + func Test_Postgres_Close(t *testing.T) { utils.AssertEqual(t, nil, testStore.Close()) }