add router switch and pgx changes
This commit is contained in:
@@ -20,7 +20,7 @@ var (
|
||||
pgxMutex sync.RWMutex
|
||||
)
|
||||
|
||||
func (a *App) NewPGXPool(name string) *pgxpool.Pool {
|
||||
func (a *App) newPGXPool(name string) *pgxpool.Pool {
|
||||
pgxMutex.Lock()
|
||||
defer pgxMutex.Unlock()
|
||||
|
||||
@@ -44,22 +44,32 @@ func (a *App) NewPGXPool(name string) *pgxpool.Pool {
|
||||
return dbPool
|
||||
}
|
||||
|
||||
func (a *App) GetPGXPool(name string) (*pgxpool.Pool, bool) {
|
||||
func (a *App) GetPGXPool(name string) *pgxpool.Pool {
|
||||
pgxMutex.RLock()
|
||||
defer pgxMutex.RUnlock()
|
||||
|
||||
pool, exists := pgxPools[name]
|
||||
return pool, exists
|
||||
if !exists {
|
||||
slog.Error("database connection not found", "name", name)
|
||||
return nil
|
||||
}
|
||||
|
||||
return pool
|
||||
}
|
||||
|
||||
func (a *App) ClosePGXPools() {
|
||||
func (a *App) ClosePGXPool(name string) {
|
||||
pgxMutex.Lock()
|
||||
defer pgxMutex.Unlock()
|
||||
|
||||
for name, pool := range pgxPools {
|
||||
pool.Close()
|
||||
delete(pgxPools, name)
|
||||
slog.Info("closed database connection", "name", name)
|
||||
pool, exists := pgxPools[name]
|
||||
if !exists {
|
||||
slog.Error("database connection not found", "name", name)
|
||||
return
|
||||
}
|
||||
|
||||
pool.Close()
|
||||
delete(pgxPools, name)
|
||||
slog.Info("closed database connection", "name", name)
|
||||
}
|
||||
|
||||
func NumericToFloat64(n pgtype.Numeric) float64 {
|
||||
@@ -90,7 +100,7 @@ func NumericToInt64(n pgtype.Numeric) int64 {
|
||||
|
||||
func FloatToNumeric(number float64, precision int) (value pgtype.Numeric) {
|
||||
parse := strconv.FormatFloat(number, 'f', precision, 64)
|
||||
slog.Info("parse", "parse", parse)
|
||||
slog.Debug("parse", "parse", parse)
|
||||
|
||||
if err := value.Scan(parse); err != nil {
|
||||
slog.Error("error scanning numeric", "error", err)
|
||||
|
||||
Reference in New Issue
Block a user