add repository draft
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
_ "github.com/jackc/pgx/v5/stdlib"
|
||||
)
|
||||
|
||||
func NewPGXPool(datasource string) *pgxpool.Pool {
|
||||
dbPool, err := pgxpool.New(context.Background(), datasource)
|
||||
if err != nil {
|
||||
slog.Error("error connecting to database", "error", err, "datasource", datasource)
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if err := dbPool.Ping(context.Background()); err != nil {
|
||||
slog.Error("error pinging database, maybe incorrect datasource", "error", err, "datasource", datasource)
|
||||
panic(err)
|
||||
}
|
||||
slog.Info("connected to database", "datasource", datasource)
|
||||
return dbPool
|
||||
}
|
||||
Reference in New Issue
Block a user