diff --git a/postgres/README.md b/postgres/v2/README.md similarity index 100% rename from postgres/README.md rename to postgres/v2/README.md diff --git a/postgres/config.go b/postgres/v2/config.go similarity index 86% rename from postgres/config.go rename to postgres/v2/config.go index b01b222f..9b81cb2f 100644 --- a/postgres/config.go +++ b/postgres/v2/config.go @@ -1,7 +1,7 @@ -package postgres +package v2 import ( - "github.com/jackc/pgx/v4/pgxpool" + "github.com/jackc/pgx/pgxpool" "time" ) @@ -30,9 +30,9 @@ type Config struct { // ConfigDefault is the default config var ConfigDefault = Config{ - Table: "fiber_storage", - Reset: false, - GCInterval: 10 * time.Second, + Table: "fiber_storage", + Reset: false, + GCInterval: 10 * time.Second, } // Helper function to set default values diff --git a/postgres/postgres.go b/postgres/v2/postgres.go similarity index 96% rename from postgres/postgres.go rename to postgres/v2/postgres.go index 84ced67d..f97a6d29 100644 --- a/postgres/postgres.go +++ b/postgres/v2/postgres.go @@ -1,10 +1,12 @@ -package postgres +package v2 import ( "context" "database/sql" + "errors" "fmt" "github.com/jackc/pgx/v4/pgxpool" + "reflect" "strings" "time" ) @@ -45,6 +47,10 @@ func New(config ...Config) *Storage { db := cfg.Db + if reflect.ValueOf(db).IsNil() { + panic(errors.New("db pool instance must be passed into the config")) + } + // Ping database if err := db.Ping(context.Background()); err != nil { panic(err) @@ -180,4 +186,4 @@ func (s *Storage) checkSchema(tableName string) { if strings.ToLower(string(data)) != "bytea" { fmt.Printf(checkSchemaMsg, string(data)) } -} \ No newline at end of file +} diff --git a/postgres/postgres_test.go b/postgres/v2/postgres_test.go similarity index 98% rename from postgres/postgres_test.go rename to postgres/v2/postgres_test.go index fb7953d7..5decfa50 100644 --- a/postgres/postgres_test.go +++ b/postgres/v2/postgres_test.go @@ -1,4 +1,4 @@ -package postgres +package v2 import ( "context" @@ -10,7 +10,7 @@ import ( ) var testStore = New(Config{ - Reset: true, + Reset: true, }) func Test_Postgres_Set(t *testing.T) { @@ -163,7 +163,7 @@ func Test_SslRequiredMode(t *testing.T) { } }() _ = New(Config{ - Reset: true, + Reset: true, }) }