Files
mtusi2026lab7/internal/adapter/postgres/store.go
T
d1frend cc41f601e3
Skeleton contracts / contracts (pull_request) Canceled after 0s
на оценку 4
2026-11-22 23:33:11 +03:00

44 lines
840 B
Go

package postgres
import (
"context"
"sync/atomic"
"time"
"github.com/jackc/pgx/v5/pgxpool"
)
type PostgreSQLStore struct {
pool *pgxpool.Pool
queryTimeout time.Duration
expiredStatePruneCounter atomic.Uint64
loginRatePruneCounter atomic.Uint64
}
func NewPostgreSQLStore(
pool *pgxpool.Pool,
queryTimeout time.Duration,
) *PostgreSQLStore {
return &PostgreSQLStore{
pool: pool,
queryTimeout: queryTimeout,
}
}
func (s *PostgreSQLStore) Ping(ctx context.Context) error {
queryContext, cancel := s.withTimeout(ctx)
defer cancel()
return s.pool.Ping(queryContext)
}
func (s *PostgreSQLStore) Close() {
s.pool.Close()
}
func (s *PostgreSQLStore) withTimeout(
ctx context.Context,
) (context.Context, context.CancelFunc) {
return context.WithTimeout(ctx, s.queryTimeout)
}