data

package
v0.0.0-...-b497eb9 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Close

func Close() error

Close closes the resources used by data.

func MakeMigration

func MakeMigration(db *sql.DB) error

MakeMigration creates all the tables in the database

Types

type Data

type Data struct {
	DB *sql.DB
}

Data manages the connection to the database.

func New

func New() *Data

New returns a new instance of Data with the database connection ready.

type GameRepository

type GameRepository struct {
	Data *Data
}

GameRepository manages the operations with the database that correspond to the game model.

func (*GameRepository) Create

func (gr *GameRepository) Create(ctx context.Context, game *game.Game) error

Create adds a new game.

func (*GameRepository) Delete

func (gr *GameRepository) Delete(ctx context.Context, id uint) error

Delete removes a game by id.

func (*GameRepository) GetAll

func (gr *GameRepository) GetAll(ctx context.Context) ([]game.Game, error)

GetAll returns all public started games.

func (*GameRepository) GetByUser

func (gr *GameRepository) GetByUser(ctx context.Context, userID uint) ([]game.Game, error)

GetByUser returns all user ended games.

func (*GameRepository) GetOne

func (gr *GameRepository) GetOne(ctx context.Context, gamename string) (game.Game, error)

GetOne returns one started game by name.

func (*GameRepository) Update

func (gr *GameRepository) Update(ctx context.Context, id uint, game game.Game) error

Update updates a game by id.

type UserRepository

type UserRepository struct {
	Data *Data
}

UserRepository manages the operations with the database that correspond to the user model.

func (*UserRepository) Create

func (ur *UserRepository) Create(ctx context.Context, u *user.User) error

Create adds a new user.

func (*UserRepository) Delete

func (ur *UserRepository) Delete(ctx context.Context, id uint) error

Delete removes a user by id.

func (*UserRepository) GetByUsername

func (ur *UserRepository) GetByUsername(ctx context.Context, username string) (user.User, error)

GetByUsername returns one user by username.

func (*UserRepository) Update

func (ur *UserRepository) Update(ctx context.Context, id uint, u user.User) error

Update updates a user by id.

Jump to

Keyboard shortcuts

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