postgres

package
v0.0.0-...-b7ca9ae Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const MAX_GAMES = 100

Maximum number of games to query

Variables

This section is empty.

Functions

This section is empty.

Types

type AvalonPostgresStorage

type AvalonPostgresStorage struct {
	Pool *pgxpool.Pool
}

func NewAvalonPostgresStorage

func NewAvalonPostgresStorage(
	ctx context.Context,
	connString string,
) (
	store *AvalonPostgresStorage,
	cleanup func(),
	err error,
)

func (*AvalonPostgresStorage) CreatePlayer

func (s *AvalonPostgresStorage) CreatePlayer(
	ctx context.Context,
	player *avalon.PlayerImpl,
) error

func (*AvalonPostgresStorage) GetGame

func (s *AvalonPostgresStorage) GetGame(
	ctx context.Context,
	id avalon.GameId,
) (game *avalon.GameImpl, err error)

func (*AvalonPostgresStorage) GetGames

func (s *AvalonPostgresStorage) GetGames(
	ctx context.Context,
) (games []*avalon.GameImpl, err error)

func (*AvalonPostgresStorage) GetPlayer

func (s *AvalonPostgresStorage) GetPlayer(
	ctx context.Context,
	playerId avalon.PlayerId,
) (player *avalon.PlayerImpl, err error)

func (*AvalonPostgresStorage) GetPlayersById

func (s *AvalonPostgresStorage) GetPlayersById(
	ctx context.Context,
	playerIds []avalon.PlayerId,
) (map[avalon.PlayerId]*avalon.PlayerImpl, error)

func (*AvalonPostgresStorage) RunMigrations

func (s *AvalonPostgresStorage) RunMigrations(
	ctx context.Context,
	migrationFilesPath string,
) error

func (*AvalonPostgresStorage) SaveGame

func (s *AvalonPostgresStorage) SaveGame(ctx context.Context, game *avalon.GameImpl) error

func (*AvalonPostgresStorage) UpdatePlayers

func (s *AvalonPostgresStorage) UpdatePlayers(
	ctx context.Context,
	players []*avalon.PlayerImpl,
) error

func (*AvalonPostgresStorage) WithTx

func (s *AvalonPostgresStorage) WithTx(
	ctx context.Context,
	perform func(context.Context, pgx.Tx) error,
) (err error)

type GameEntry

type GameEntry struct {
	Id        pgtype.Text
	BlueWon   pgtype.Bool
	CreatedAt pgtype.Timestamp
}

A row for `games` table in db

type GameQueryOpts

type GameQueryOpts struct {
	Id avalon.GameId
}

type JoinedPlayersByGame

type JoinedPlayersByGame struct {
	GameEntry
	PlayersByGameEntry
}

A row from the results when joining `players_by_name` and `games` tables

type PlayerEntry

type PlayerEntry struct {
	Id       pgtype.Text
	Name     pgtype.Text
	Rating   pgtype.Float8
	NumGames pgtype.Int8
}

type PlayersByGameEntry

type PlayersByGameEntry struct {
	GameId         pgtype.Text
	PlayerId       pgtype.Text
	PlayerName     pgtype.Text
	PlayerRating   pgtype.Float8
	PlayerNumGames pgtype.Int8
	PlayerRole     pgtype.Text
}

A row for `players_by_game` table in db

type PlayersByGameEntryForWriting

type PlayersByGameEntryForWriting struct {
	GameId         avalon.GameId
	PlayerId       avalon.PlayerId
	PlayerName     string
	PlayerRating   float64
	PlayerNumGames int
	PlayerRole     avalon.Role
}

Jump to

Keyboard shortcuts

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