mirror of
https://github.com/gofiber/storage.git
synced 2025-10-04 08:16:36 +08:00
Moved new postgres implementation to v2 folder, also added nil check for db object in postgres config
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
package postgres
|
package v2
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/jackc/pgx/v4/pgxpool"
|
"github.com/jackc/pgx/pgxpool"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -30,9 +30,9 @@ type Config struct {
|
|||||||
|
|
||||||
// ConfigDefault is the default config
|
// ConfigDefault is the default config
|
||||||
var ConfigDefault = Config{
|
var ConfigDefault = Config{
|
||||||
Table: "fiber_storage",
|
Table: "fiber_storage",
|
||||||
Reset: false,
|
Reset: false,
|
||||||
GCInterval: 10 * time.Second,
|
GCInterval: 10 * time.Second,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper function to set default values
|
// Helper function to set default values
|
@@ -1,10 +1,12 @@
|
|||||||
package postgres
|
package v2
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/jackc/pgx/v4/pgxpool"
|
"github.com/jackc/pgx/v4/pgxpool"
|
||||||
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@@ -45,6 +47,10 @@ func New(config ...Config) *Storage {
|
|||||||
|
|
||||||
db := cfg.Db
|
db := cfg.Db
|
||||||
|
|
||||||
|
if reflect.ValueOf(db).IsNil() {
|
||||||
|
panic(errors.New("db pool instance must be passed into the config"))
|
||||||
|
}
|
||||||
|
|
||||||
// Ping database
|
// Ping database
|
||||||
if err := db.Ping(context.Background()); err != nil {
|
if err := db.Ping(context.Background()); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@@ -180,4 +186,4 @@ func (s *Storage) checkSchema(tableName string) {
|
|||||||
if strings.ToLower(string(data)) != "bytea" {
|
if strings.ToLower(string(data)) != "bytea" {
|
||||||
fmt.Printf(checkSchemaMsg, string(data))
|
fmt.Printf(checkSchemaMsg, string(data))
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,4 +1,4 @@
|
|||||||
package postgres
|
package v2
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@@ -10,7 +10,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var testStore = New(Config{
|
var testStore = New(Config{
|
||||||
Reset: true,
|
Reset: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
func Test_Postgres_Set(t *testing.T) {
|
func Test_Postgres_Set(t *testing.T) {
|
||||||
@@ -163,7 +163,7 @@ func Test_SslRequiredMode(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
_ = New(Config{
|
_ = New(Config{
|
||||||
Reset: true,
|
Reset: true,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue
Block a user