repositories

package
v0.0.0-...-96f858f Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsNameExists

func IsNameExists(err error) bool

func IsNotFound

func IsNotFound(err error) bool

Types

type ErrNameExists

type ErrNameExists struct {
}

func (*ErrNameExists) Error

func (e *ErrNameExists) Error() string

type ErrNotFound

type ErrNotFound struct {
}

func (*ErrNotFound) Error

func (e *ErrNotFound) Error() string

type PostgresRepository

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

func (*PostgresRepository) Close

func (r *PostgresRepository) Close(ctx context.Context) error

func (*PostgresRepository) CountCharacters

func (r *PostgresRepository) CountCharacters(ctx context.Context, userID string) (int, error)

func (*PostgresRepository) CreateCharacter

func (r *PostgresRepository) CreateCharacter(ctx context.Context, userID string, name string) (*models.Character, error)

func (*PostgresRepository) CreateUser

func (r *PostgresRepository) CreateUser(ctx context.Context, userID string) (*models.User, error)

func (*PostgresRepository) DeleteCharacter

func (r *PostgresRepository) DeleteCharacter(ctx context.Context, userID string, characterID int32) error

func (*PostgresRepository) GetCharacter

func (r *PostgresRepository) GetCharacter(ctx context.Context, userID string, characterID int32) (*models.Character, error)

func (*PostgresRepository) ListCharacters

func (r *PostgresRepository) ListCharacters(ctx context.Context, userID string) ([]*models.Character, error)

func (*PostgresRepository) LoadPlayerState

func (r *PostgresRepository) LoadPlayerState(ctx context.Context, characterID int32) (*gametypes.PlayerState, error)

func (*PostgresRepository) NameExists

func (r *PostgresRepository) NameExists(ctx context.Context, name string) (bool, error)

func (*PostgresRepository) SaveGameState

func (r *PostgresRepository) SaveGameState(ctx context.Context, gameState *gametypes.GameState) error

func (*PostgresRepository) SavePlayerState

func (r *PostgresRepository) SavePlayerState(ctx context.Context, timestamp int64, characterID int32, playerState *gametypes.PlayerState) error

type Repository

type Repository interface {
	Close(ctx context.Context) error

	CreateUser(ctx context.Context, userID string) (*models.User, error)
	ListCharacters(ctx context.Context, userID string) ([]*models.Character, error)
	CountCharacters(ctx context.Context, userID string) (int, error)
	GetCharacter(ctx context.Context, userID string, characterID int32) (*models.Character, error)
	CreateCharacter(ctx context.Context, userID string, name string) (*models.Character, error)
	DeleteCharacter(ctx context.Context, userID string, characterID int32) error
	NameExists(ctx context.Context, name string) (bool, error)

	SaveGameState(ctx context.Context, gameState *gametypes.GameState) error
	SavePlayerState(ctx context.Context, timestamp int64, characterID int32, playerState *gametypes.PlayerState) error
	LoadPlayerState(ctx context.Context, characterID int32) (*gametypes.PlayerState, error)
}

func NewPostgresRepository

func NewPostgresRepository(ctx context.Context, connStr string) (Repository, error)

NewPostgresRepository creates a new PSQLRepository. It panics if it is unable to connect to the database after 2 minutes. The caller is responsible for calling Close() on the repository.

func NewSQLiteRepository

func NewSQLiteRepository(ctx context.Context, path string, migrations string) (Repository, error)

type SQLiteRepository

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

func (*SQLiteRepository) Close

func (r *SQLiteRepository) Close(ctx context.Context) error

func (*SQLiteRepository) CountCharacters

func (r *SQLiteRepository) CountCharacters(ctx context.Context, userID string) (int, error)

func (*SQLiteRepository) CreateCharacter

func (r *SQLiteRepository) CreateCharacter(ctx context.Context, userID string, name string) (*models.Character, error)

func (*SQLiteRepository) CreateUser

func (r *SQLiteRepository) CreateUser(ctx context.Context, userID string) (*models.User, error)

func (*SQLiteRepository) DeleteCharacter

func (r *SQLiteRepository) DeleteCharacter(ctx context.Context, userID string, characterID int32) error

func (*SQLiteRepository) GetCharacter

func (r *SQLiteRepository) GetCharacter(ctx context.Context, userID string, characterID int32) (*models.Character, error)

func (*SQLiteRepository) ListCharacters

func (r *SQLiteRepository) ListCharacters(ctx context.Context, userID string) ([]*models.Character, error)

func (*SQLiteRepository) LoadPlayerState

func (r *SQLiteRepository) LoadPlayerState(ctx context.Context, characterID int32) (*gametypes.PlayerState, error)

func (*SQLiteRepository) NameExists

func (r *SQLiteRepository) NameExists(ctx context.Context, name string) (bool, error)

func (*SQLiteRepository) SaveGameState

func (r *SQLiteRepository) SaveGameState(ctx context.Context, gameState *gametypes.GameState) error

func (*SQLiteRepository) SavePlayerState

func (r *SQLiteRepository) SavePlayerState(ctx context.Context, timestamp int64, characterID int32, playerState *gametypes.PlayerState) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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