postgres

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 1, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidRankStatuID = errors.New("invalid rank status id")
)

Functions

func CreateListRankOption

func CreateListRankOption(history []Match) [][2]ListRankOption

Should be unexported

func NewStore

func NewStore(pool *pgxpool.Pool) internal.Store

func ParticipantDetailFromPG

func ParticipantDetailFromPG(participant Participant, summoner Summoner, currentRank, rankBefore, rankAfter *RankFull) internal.ParticipantDetailOption

func WithPostgresRankStatus2 deprecated

func WithPostgresRankStatus2(rank *RankFull) internal.RankStatusOption

Deprecated: not using.

func WithPostgresSummonerMatch deprecated

func WithPostgresSummonerMatch(match Match, participant Participant, rankBefore, rankAfter *RankFull) internal.SummonerMatchOption

Deprecated: not using.

Types

type BatchTx

type BatchTx interface {
	Queue(query string, arguments ...any) *pgx.QueuedQuery
}

type ListRankOption

type ListRankOption struct {
	// Start indicates an inclusive lower bound on the date.
	Start *time.Time

	// End indicates an exclusive upper bound on the date.
	End *time.Time

	Offset, Limit uint

	Recent bool
}

type Match

type Match struct {
	ID string `db:"match_id"`

	Date time.Time `db:"date"`

	Duration time.Duration `db:"duration"`

	Version string `db:"version"`

	WinnerID int `db:"winner"`
}

type MatchStore

type MatchStore struct{ Tx Tx }

MatchStore manages match objects.

func (*MatchStore) CreateMatch

func (db *MatchStore) CreateMatch(ctx context.Context, match Match) error

func (*MatchStore) CreateMatchInBatch

func (db *MatchStore) CreateMatchInBatch(tx BatchTx, match Match)

func (*MatchStore) CreateParticipant

func (db *MatchStore) CreateParticipant(ctx context.Context, participant Participant) error

func (*MatchStore) CreateParticipantInBatch

func (db *MatchStore) CreateParticipantInBatch(tx BatchTx, participant Participant)

func (*MatchStore) GetMatch

func (db *MatchStore) GetMatch(ctx context.Context, id string) (Match, error)

func (*MatchStore) GetNewMatchIDs

func (db *MatchStore) GetNewMatchIDs(ctx context.Context, ids []string) (newIDs []string, err error)

func (*MatchStore) GetParticipant

func (db *MatchStore) GetParticipant(ctx context.Context, puuid riot.PUUID, matchID string) (Participant, error)

func (*MatchStore) GetParticipants

func (db *MatchStore) GetParticipants(ctx context.Context, id string) ([]Participant, error)

func (*MatchStore) GetSummonerChampions

func (db *MatchStore) GetSummonerChampions(ctx context.Context, puuid riot.PUUID, start, end time.Time) ([]internal.SummonerChampion, error)

func (*MatchStore) ListMatchHistoryIDs

func (db *MatchStore) ListMatchHistoryIDs(ctx context.Context, puuid riot.PUUID, start, end time.Time) ([]string, error)

type Migrator

type Migrator struct {
}

type PGInstance

type PGInstance struct {
	// contains filtered or unexported fields
}

func NewPGInstance

func NewPGInstance(ctx context.Context, migrationsPath string) *PGInstance

NewPGInstance sets up a postgres server in a docker container. It will use the current schema version.

func (*PGInstance) SetupConn

func (p *PGInstance) SetupConn(ctx context.Context, t testing.TB) *pgxpool.Pool

func (*PGInstance) SetupStore

func (p *PGInstance) SetupStore(ctx context.Context, t testing.TB) internal.Store

SetupStore creates an empty store, and will clean up after test t finishes.

func (*PGInstance) Terminate

func (p *PGInstance) Terminate(ctx context.Context) error

type Participant

type Participant struct {
	PUUID string `db:"puuid"`

	MatchID string `db:"match_id"`

	TeamID int `db:"team"`

	ChampionID int `db:"champion"`

	ChampionLevel int `db:"champion_level"`

	TeamPosition string `db:"position"`

	SummonerIDs [2]int `db:"summoners"`

	Runes [11]int `db:"runes"`

	Items [7]int `db:"items"`

	Kills int `db:"kills"`

	Deaths int `db:"deaths"`

	Assists int `db:"assists"`

	KillParticipation float32 `db:"kill_participation"`

	CreepScore int `db:"creep_score"`

	CreepScorePerMinute float32 `db:"creep_score_per_minute"`

	DamageDealt int `db:"damage_dealt"`

	DamageTaken int `db:"damage_taken"`

	DamageDeltaEnemy int `db:"damage_delta_enemy"`

	DamagePercentageTeam float32 `db:"damage_percentage_team"`

	GoldEarned int `db:"gold_earned"`

	GoldDeltaEnemy int `db:"gold_delta_enemy"`

	GoldPercentageTeam float32 `db:"gold_percentage_team"`

	VisionScore int `db:"vision_score"`

	PinkWardsBought int `db:"pink_wards_bought"`
}

type PostgresSearchResult2

type PostgresSearchResult2 struct {
	Summoner Summoner

	Status *RankStatus
	Detail *RankDetail
}

func (*PostgresSearchResult2) Convert

type PostgresToRankStatus

type PostgresToRankStatus struct {
	Status RankStatus
	Detail *RankDetail
}

func (PostgresToRankStatus) Map

type PostgresToSummonerMatchMapper

type PostgresToSummonerMatchMapper struct {
	Match Match

	Participant Participant

	BeforeStatus *RankStatus
	BeforeDetail *RankDetail

	AfterStatus *RankStatus
	AfterDetail *RankDetail
}

func (PostgresToSummonerMatchMapper) Map

type RankDetail

type RankDetail struct {
	RankStatusID int `db:"rank_status_id"`

	Wins int `db:"wins"`

	Losses int `db:"losses"`

	Tier string `db:"tier"`

	Division string `db:"division"`

	LP int `db:"lp"`
}

type RankFull

type RankFull struct {
	Status RankStatus
	Detail *RankDetail
}

type RankStatus

type RankStatus struct {
	PUUID string `db:"puuid"`

	EffectiveDate time.Time `db:"effective_date"`

	// IsRanked indicates that there exists a [RankDetail] for this status.
	IsRanked bool `db:"is_ranked"`
}

RankStatus is always created when a rank request is made.

type RankStore

type RankStore struct{ Tx Tx }

func (*RankStore) CreateRankDetail

func (db *RankStore) CreateRankDetail(ctx context.Context, detail RankDetail) error

func (*RankStore) CreateRankStatus

func (db *RankStore) CreateRankStatus(ctx context.Context, status RankStatus) (id int, err error)

CreateRankStatus creates a rank status and returns created id.

func (*RankStore) GetRankDetail

func (db *RankStore) GetRankDetail(ctx context.Context, id int) (RankDetail, error)

func (*RankStore) GetRankStatus

func (db *RankStore) GetRankStatus(ctx context.Context, id int) (status RankStatus, err error)

func (*RankStore) ListRankIDs

func (db *RankStore) ListRankIDs(ctx context.Context, puuid riot.PUUID, option ListRankOption) ([]int, error)

type Store

type Store struct {
	Pool *pgxpool.Pool
}

Store manages connections with a postgres database.

func (*Store) GetChampions

func (db *Store) GetChampions(ctx context.Context, puuid riot.PUUID, start, end time.Time) ([]internal.SummonerChampion, error)

func (*Store) GetMatchDetail

func (db *Store) GetMatchDetail(ctx context.Context, id string) (_ internal.MatchDetail, err error)

func (*Store) GetMatchHistory

func (db *Store) GetMatchHistory(ctx context.Context, puuid riot.PUUID, start, end time.Time) (matches []internal.SummonerMatch, err error)

func (*Store) GetNewMatchIDs

func (db *Store) GetNewMatchIDs(ctx context.Context, ids []string) (newIDs []string, err error)

func (*Store) GetProfileDetail

func (db *Store) GetProfileDetail(ctx context.Context, puuid riot.PUUID) (m internal.ProfileDetail, err error)

func (*Store) RecordMatch

func (db *Store) RecordMatch(ctx context.Context, match internal.Match) error

func (*Store) RecordProfile

func (db *Store) RecordProfile(ctx context.Context, summoner internal.Profile) error

func (*Store) SearchSummoner

func (db *Store) SearchSummoner(ctx context.Context, q string) ([]internal.SearchResult, error)

type Summoner

type Summoner struct {
	PUUID riot.PUUID

	Name, Tagline string
}

type SummonerStore

type SummonerStore struct{ Tx Tx }

SummonerStore manages summoner objects.

func (*SummonerStore) CreateSummoner

func (db *SummonerStore) CreateSummoner(ctx context.Context, summoner Summoner) error

func (*SummonerStore) GetSummoner

func (db *SummonerStore) GetSummoner(ctx context.Context, puuid riot.PUUID) (_ Summoner, err error)

func (*SummonerStore) SearchSummoner

func (db *SummonerStore) SearchSummoner(ctx context.Context, q string) ([]Summoner, error)

TODO: switch to fuzzy match algorithm.

type Tx

type Tx interface {
	Exec(ctx context.Context, sql string, args ...any) (commandTag pgconn.CommandTag, err error)

	Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)

	QueryRow(ctx context.Context, sql string, args ...any) pgx.Row
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL