mirror of
https://github.com/gofiber/storage.git
synced 2025-10-05 08:37:10 +08:00
add conn
This commit is contained in:
@@ -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) Delete(key string) error
|
||||||
func (s *Storage) Reset() error
|
func (s *Storage) Reset() error
|
||||||
func (s *Storage) Close() error
|
func (s *Storage) Close() error
|
||||||
|
func (s *Storage) Conn() *pgxpool.Pool
|
||||||
```
|
```
|
||||||
### Installation
|
### 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:
|
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:
|
||||||
|
@@ -160,6 +160,11 @@ func (s *Storage) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return database client
|
||||||
|
func (s *Storage) Conn() *pgxpool.Pool {
|
||||||
|
return s.db
|
||||||
|
}
|
||||||
|
|
||||||
// gcTicker starts the gc ticker
|
// gcTicker starts the gc ticker
|
||||||
func (s *Storage) gcTicker() {
|
func (s *Storage) gcTicker() {
|
||||||
ticker := time.NewTicker(s.gcInterval)
|
ticker := time.NewTicker(s.gcInterval)
|
||||||
|
@@ -3,6 +3,7 @@ package v2
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -10,7 +11,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var testStore = New(Config{
|
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) {
|
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) {
|
func Test_Postgres_Close(t *testing.T) {
|
||||||
utils.AssertEqual(t, nil, testStore.Close())
|
utils.AssertEqual(t, nil, testStore.Close())
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user