func (s *Service) hasTx(ctx context.Context) bool {
	if ctx == nil {
		return false
	}
	_, ok := ctx.Value(&Tx{}).(pgx.Tx)
	return ok
}
hasTx returns true if the context has a transaction.
package postgresql
import (
	"context"
	"github.com/jackc/pgx/v4"
	"github.com/pkg/errors"
)
var (
	ErrNoTransaction = errors.New("no transaction for action")
)
type Tx struct{}
func (s *Service) BeginTx(ctx context.Context) (context.Context, context.CancelFunc, error) {
	ctx, cancel := context.WithCancel(ctx)
	tx, err := s.pool.Begin(ctx)
	if err != nil {
		cancel()
		return nil, nil, errors.Wrap(err, "failed to begin transaction")
	}
	ctx = context.WithValue(ctx, &Tx{}, tx)
	return ctx, func() {
		if err := tx.Rollback(ctx); err != nil {
			log.Warn().Err(err).Msg("Failed to rollback transaction")
		}
		cancel()
	}, nil
}