database

package
v0.0.0-...-8107f3e Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//Driver is a name of db driver (requires go get github.com/mattn/go-sqlite3)
	Driver = "sqlite3"
	//Path is a path to file with database
	Path = "database/CandyWarGoDatabase.sqlite"
)

Variables

This section is empty.

Functions

func ResetTables

func ResetTables() error

Types

type DBHandler

type DBHandler struct {
	DriverName string
	DBPath     string
	Connection *sql.DB
}

DBHandler holds interfaces to interact with database

func NewDBHandler

func NewDBHandler() (*DBHandler, error)

NewDBHandler returns pointer to the default ready to use DBHandler

func NewDBHandlerWithPath

func NewDBHandlerWithPath(path string) (*DBHandler, error)

NewDBHandler returns pointer to the default ready to use DBHandler

func (*DBHandler) Connect

func (dbh *DBHandler) Connect() error

Connect creates connection with database file by driver

func (*DBHandler) ContainsPlayer

func (dbh *DBHandler) ContainsPlayer(player models.Player) (bool, error)

ContainsPlayer returns true if a player with the specified id is already registered

func (*DBHandler) ContainsUser

func (dbh *DBHandler) ContainsUser(user api.User) (bool, error)

ContainsUser returns true if a user with the specified id is already registered

func (*DBHandler) CreateGamesTable

func (dbh *DBHandler) CreateGamesTable() error

CreateGamesTable creates a table for games info, active player and his time mark for permission to start move

func (*DBHandler) CreatePlayersTable

func (dbh *DBHandler) CreatePlayersTable() error

CreatePlayersTable creates a table of Players if one does not already exist

func (*DBHandler) CreateTables

func (dbh *DBHandler) CreateTables() error

CreateTables is a shortcut to create all necessary tables

func (*DBHandler) CreateUsersTable

func (dbh *DBHandler) CreateUsersTable() error

CreateUsersTable creates a table of Users if one does not already exist

func (*DBHandler) GetField

func (dbh *DBHandler) GetField(table, field, whereField string, whereVal interface{}) interface{}

GetField returns value of field in given table in respect to to some parameter

func (*DBHandler) GetGameByID

func (dbh *DBHandler) GetGameByID(id int) (*game_model.Game, error)

GetGameByID returns game.Game object from database with specified id

func (*DBHandler) GetGames

func (dbh *DBHandler) GetGames() []*game_model.Game

GetGames returns array of all current games

func (*DBHandler) GetPlayerByID

func (dbh *DBHandler) GetPlayerByID(id int) (*models.Player, error)

GetPlayerByID returns models.Player object from database with specified id

func (*DBHandler) GetUserByID

func (dbh *DBHandler) GetUserByID(id int) (*api.User, error)

GetUserByID returns api.User object from database with specified id

func (*DBHandler) InsertGame

func (dbh *DBHandler) InsertGame(game game_model.Game) error

InsertGame adds a game to the Games table

func (*DBHandler) InsertPlayer

func (dbh *DBHandler) InsertPlayer(player models.Player) error

InsertPlayer adds a user to the Users table

func (*DBHandler) InsertUser

func (dbh *DBHandler) InsertUser(user api.User) error

InsertUser adds a user to the Users table

func (*DBHandler) NameExists

func (dbh *DBHandler) NameExists(name string) (bool, error)

NameExists returns true if a user with the same name is already registered

func (*DBHandler) Update

func (dbh *DBHandler) Update(table, field string, value interface{}, whereField string, whereValue interface{}) error

Update updates any field in any table with new value

Jump to

Keyboard shortcuts

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