generated from VLADIMIR/template
clear
This commit is contained in:
@@ -18,6 +18,7 @@ import (
|
||||
"evening_detective_server/internal/repos/game_map_repo"
|
||||
"evening_detective_server/internal/repos/game_reviews_repo"
|
||||
"evening_detective_server/internal/repos/games_repo"
|
||||
"evening_detective_server/internal/repos/health_repo"
|
||||
"evening_detective_server/internal/repos/refresh_tokens_repo"
|
||||
"evening_detective_server/internal/repos/scenarios_repo"
|
||||
"evening_detective_server/internal/repos/screen_sessions_repo"
|
||||
@@ -84,11 +85,8 @@ func main() {
|
||||
log.Fatalf("Unable to create connection pool: %v\n", err)
|
||||
}
|
||||
defer dbpool.Close()
|
||||
|
||||
// Test request to DB
|
||||
var greeting string
|
||||
if err = dbpool.QueryRow(context.Background(), "select 'Hello, world!'").Scan(&greeting); err != nil {
|
||||
log.Fatalf("QueryRow failed: %v\n", err)
|
||||
if err := health_repo.New(dbpool).Check(context.Background()); err != nil {
|
||||
log.Fatalf("database check failed: %v\n", err)
|
||||
}
|
||||
|
||||
usersRepo := users_repo.NewUserRepo(dbpool)
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package health_repo
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
)
|
||||
|
||||
type Repo struct {
|
||||
pool *pgxpool.Pool
|
||||
}
|
||||
|
||||
func New(pool *pgxpool.Pool) *Repo {
|
||||
return &Repo{pool: pool}
|
||||
}
|
||||
|
||||
func (r *Repo) Check(ctx context.Context) error {
|
||||
return r.pool.Ping(ctx)
|
||||
}
|
||||
Reference in New Issue
Block a user