hexzsql

package
v0.0.0-...-5adaefb Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUserNotFound      = errors.New("user not found")
	ErrUserAlreadyExists = errors.New("user already exists")
	ErrInvalidToken      = errors.New("invalid or non-existing token")
)

Functions

This section is empty.

Types

type AccountStatus

type AccountStatus int
const (
	AccountStatusNew     AccountStatus = 0
	AccountStatusActive  AccountStatus = 1
	AccountStatusBlocked AccountStatus = 2
	AccountStatusDeleted AccountStatus = 3
)

type DatabaseStore

type DatabaseStore interface {
	GameStore
	UserStore
}

type GameRow

type GameRow struct {
	Created       time.Time
	GameID        string
	Started       time.Time
	GameType      api.GameType
	CPUPlayerMode pb.CPUPlayerMode_Enum
	Host          string
	HostID        string
	Move          int
	ScoreP1       int
	ScoreP2       int
	Done          bool
}

type GameStore

type GameStore interface {
	// Stores a game state in the database.
	StoreGame(ctx context.Context, hostId string, state *pb.GameState) error
	// Adds an entry to the game history.
	// If boardStatus is not nil, the game table will get updated with the status information.
	InsertHistory(ctx context.Context, entryType string, gameId string, state *pb.GameState, boardStatus *api.BoardStatus) error
	// Adds stats for a CPU move.
	InsertStats(ctx context.Context, stats *api.WASMStatsRequest) error
	// Loads the latest game state.
	LoadGame(ctx context.Context, gameId string) (*pb.GameState, error)
	// Lists the `limit` most recent games, skipping `offset` many (for paging).
	// Games without a single move are not included in the result.
	ListRecentGames(ctx context.Context, offset int, limit int) ([]*GameRow, error)
}

type PostgresStore

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

func NewPostgresStore

func NewPostgresStore(ctx context.Context, database_url string) (*PostgresStore, error)

func (*PostgresStore) AddUser

func (s *PostgresStore) AddUser(ctx context.Context, user *User) error

func (*PostgresStore) Close

func (s *PostgresStore) Close() error

func (*PostgresStore) DeleteUser

func (s *PostgresStore) DeleteUser(ctx context.Context, email string) error

func (*PostgresStore) FindUser

func (s *PostgresStore) FindUser(ctx context.Context, email string) (*User, error)

func (*PostgresStore) InsertHistory

func (s *PostgresStore) InsertHistory(ctx context.Context, entryType string, gameId string, gs *pb.GameState, boardStatus *api.BoardStatus) error

func (*PostgresStore) InsertStats

func (s *PostgresStore) InsertStats(ctx context.Context, stats *api.WASMStatsRequest) error

func (*PostgresStore) ListRecentGames

func (s *PostgresStore) ListRecentGames(ctx context.Context, offset int, limit int) ([]*GameRow, error)

func (*PostgresStore) LoadGame

func (s *PostgresStore) LoadGame(ctx context.Context, gameId string) (*pb.GameState, error)

func (*PostgresStore) StoreGame

func (s *PostgresStore) StoreGame(ctx context.Context, hostId string, gs *pb.GameState) error

func (*PostgresStore) UpdateUser

func (s *PostgresStore) UpdateUser(ctx context.Context, user *User) error

Updates an existing user in the database. The ID field must be set to the user to be updated. An error is returned if the ID is empty. UpdatedAt may be empty, in which case it will be set to "now" in the database.

func (*PostgresStore) VerifyUser

func (s *PostgresStore) VerifyUser(ctx context.Context, verificationToken string) error

type User

type User struct {
	ID                 string
	Email              string
	PasswordHash       string
	PlayerName         string
	AccountStatus      AccountStatus
	VerificationToken  string
	ResetPasswordToken string
	TokenExpiry        time.Time
	CreatedAt          time.Time
	UpdatedAt          time.Time
}

type UserStore

type UserStore interface {
	// Looks up a single user by email address.
	// Returns ErrUserNotFound if no user with the given email exists.
	FindUser(ctx context.Context, email string) (*User, error)

	// Adds a new user to the database.
	// The ID field will be populated. An error is returned if
	// it is not empty.
	// CreatedAt and UpdatedAt may be empty, in which case they
	// will be set to "now" in the database.
	AddUser(ctx context.Context, user *User) error

	// DeleteUser deletes a user from the users database.
	DeleteUser(ctx context.Context, email string) error

	// Locates a user that has the given verification token.
	// If the token is not expired, the user's account status
	// is set to `active`.
	VerifyUser(ctx context.Context, verificationToken string) error
}

Jump to

Keyboard shortcuts

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