database

package
v0.0.0-...-c84c7a3 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2019 License: MIT Imports: 8 Imported by: 0

README

How to use the database package

You can get full control over the database connection by calling database.GetConnection(), this function gives you the sqlx object used to call SQL queries.

The database has three formatting rules for the table and column names:

  1. Table names have UPPERCASE names.
  2. Column names have lowercase names.
  3. Both table names and column names use underscores to split words.

Example of usage

Look at user_test.go for example of usage. This file also shows how to ROLLBACK changes made to the database. ROLLBACK works in cohesion with START TRANSACTION.

How to connect the database to GoLand

  1. On the far right of the screen there is a button called "Database". Click it!

  2. Navigate to adding a database connection, select "MariaDB".

  3. Insert all the database information found in .cache/db-config.json - including the password.

  4. Download the drivers.

  5. Test the connection.

  6. Does it work? Great, continue the guide - if it doesn't work; ask for help.

  7. In the previously opened "Database" tab - sync the database.

  8. ???

  9. Profit

database package

USER

This table contains GOOGLE authentication data. Nothing related to lichess.

RESULT

This table contains match data, and results.

Outcome can be 3 values - "win", "draw" or "loss".

RESULT_PLATFORM_ELO

This table connect the result to an ELO platform, for example lichess.org.

PLATFORM

This table contains data about platforms we utilize, like Google and lichess.org.

PLATFORM_AUTH

Which platforms are authentication platforms?

PLATFORM_ELO

Which platforms are ELO platforms?

PLATFORM_ENDPOINT

Insert the endpoints for each platform here - use custom names to remember what is what.

PLATFORM_USER

Connect users with a platform.

AccessToken is used to gain access and identify to the PLATFORM.

VerificationKey is used to identify the USER with the PLATFORM identity.

LEAGUE

When importing a lichess.org team, create them as a LEAGUE.

So Storbukk Sjakklub is a LEAGUE.

LEAGUE_SEASON

Each league can have many seasons where ELO is reset.

For our purposes just create a season with the name CONTINUOUS when creating the LEAGUE.

GROUP

Groups are the players playing in the SEASON in the LEAGUE. For chess there will only be one player in each group, so when importing from lichess.org just create a GROUP for every single lichess.org player within the imported teams. For example a group can be the player hyge.

GROUP_USER

Connects a USER with a GROUP. This connection is made possible when using the PLATFORM_USER VerificationKey, connecting the identity of the lichess.org user with our USER - thus making it possible to connect a USER with a GROUP.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DEFAULT_CONNECTION = Connection{
	"gr8elo.cekete5hvzfh.us-east-1.rds.amazonaws.com",
	"3306",
	"admin",
	"",
	"gr8elo",
}

Functions

func Connect

func Connect()

func DeleteGroup

func DeleteGroup(id int64) error

func DeleteGroupUser

func DeleteGroupUser(group_id int64, user_id int64) error

func DeleteLeague

func DeleteLeague(id int64) error

func DeleteLeagueSeason

func DeleteLeagueSeason(league_id int64, name string) error

func DeletePlatform

func DeletePlatform(id int64) error

func DeletePlatformAuth

func DeletePlatformAuth(platform_id int64) error

func DeletePlatformElo

func DeletePlatformElo(platform_id int64) error

func DeletePlatformEndpoint

func DeletePlatformEndpoint(platform_id int64, name string) error

func DeletePlatformUser

func DeletePlatformUser(user_id int64, platform_id int64) error

func DeleteResult

func DeleteResult(id int64) error

func DeleteResultPlatformElo

func DeleteResultPlatformElo(result_id int64, platform_elo_id int64) error

func DeleteUser

func DeleteUser(id int64) error

func GetConnection

func GetConnection() *sqlx.DB

func InsertGroup

func InsertGroup(group GROUP) (*int64, error)

func InsertGroupUser

func InsertGroupUser(group_user GROUP_USER) (*int64, error)

func InsertLeague

func InsertLeague(league LEAGUE) (*int64, error)

func InsertLeagueSeason

func InsertLeagueSeason(league_season LEAGUE_SEASON) (*int64, error)

func InsertPlatform

func InsertPlatform(platform PLATFORM) (*int64, error)

func InsertPlatformAuth

func InsertPlatformAuth(platform_auth PLATFORM_AUTH) (*int64, error)

func InsertPlatformElo

func InsertPlatformElo(platform_elo PLATFORM_ELO) (*int64, error)

func InsertPlatformEndpoint

func InsertPlatformEndpoint(platform_endpoint PLATFORM_ENDPOINT) (*int64, error)

func InsertPlatformUser

func InsertPlatformUser(platform_user PLATFORM_USER) (*int64, error)

func InsertResult

func InsertResult(result RESULT) (*int64, error)

func InsertResultPlatformElo

func InsertResultPlatformElo(result_platform_elo RESULT_PLATFORM_ELO) (*int64, error)

func InsertUser

func InsertUser(user USER) (*int64, error)

func LeagueExists

func LeagueExists(leagueName string) (bool, error)

func ModifyGroup

func ModifyGroup(id int64, group GROUP) error

func ModifyLeague

func ModifyLeague(id int64, league LEAGUE) error

func ModifyLeagueSeason

func ModifyLeagueSeason(league_id int64, name string, league_season LEAGUE_SEASON) error

func ModifyPlatformEndpointPath

func ModifyPlatformEndpointPath(platform_id int64, name string, path string) error

func ModifyPlatformUser

func ModifyPlatformUser(user_id int64, platform_id int64, platform_user PLATFORM_USER) error

func ModifyResultPlatformElo

func ModifyResultPlatformElo(result_id int64, platform_elo_id int64, result_platform_elo RESULT_PLATFORM_ELO) error

func ModifyUser

func ModifyUser(id int64, user USER) error

func PlatformAuthExists

func PlatformAuthExists(platform_id int64) (*bool, error)

func PlatformEloExists

func PlatformEloExists(platform_id int64) (*bool, error)

func SelectGroupUserByGroupID

func SelectGroupUserByGroupID(group_id int64) (*[]GROUP_USER, error)

func SelectGroupUserByUserID

func SelectGroupUserByUserID(user_id int64) (*[]GROUP_USER, error)

func SelectGroups

func SelectGroups(where string) (*[]GROUP, error)

func SelectGroupsByLeagueIDAndLeagueSeasonName

func SelectGroupsByLeagueIDAndLeagueSeasonName(league_id int64, league_season_name string) (*[]GROUP, error)

func SelectLeagues

func SelectLeagues(where string) (*[]LEAGUE, error)

func SelectPlatformEndpointPath

func SelectPlatformEndpointPath(platform_id int64, name string) (*string, error)

func SelectPlatformEndpoints

func SelectPlatformEndpoints(where string) (*[]PLATFORM_ENDPOINT, error)

func SelectPlatformIDByNameAndVersion

func SelectPlatformIDByNameAndVersion(name string, version string) (*int64, error)

func SelectPlatformUserByPlatformID

func SelectPlatformUserByPlatformID(platform_id int64) (*[]PLATFORM_USER, error)

func SelectPlatformUserByUserID

func SelectPlatformUserByUserID(user_id int64) (*[]PLATFORM_USER, error)

func SelectPlatforms

func SelectPlatforms(where string) (*[]PLATFORM, error)

func SelectResultCountByGroupID

func SelectResultCountByGroupID(id int64) (*int, error)

func SelectResultLastPlayedByLeagueID

func SelectResultLastPlayedByLeagueID(league_id int64) (*time.Time, error)

func SelectResultLastPlayedByPlatformID

func SelectResultLastPlayedByPlatformID(platform_id int64) (*time.Time, error)

func SelectResultPlatformEloByPlatformID

func SelectResultPlatformEloByPlatformID(platform_id int64) (*[]RESULT_PLATFORM_ELO, error)

func SelectResultPlatformEloByResultID

func SelectResultPlatformEloByResultID(result_id int64) (*[]RESULT_PLATFORM_ELO, error)

func SelectResults

func SelectResults(where string) (*[]RESULT, error)

func SelectResultsByLeagueID

func SelectResultsByLeagueID(league_id int64) (*[]RESULT, error)

func SelectUsers

func SelectUsers(where string) (*[]USER, error)

Types

type Connection

type Connection struct {
	Host     string `json:"host"`
	Port     string `json:"port"`
	Username string `json:"username"`
	Password string `json:"password"`
	Database string `json:"database"`
}

type GROUP

type GROUP struct {
	ID               int64     `json:"id" db:"id"`
	LeagueID         int64     `json:"league_id" db:"league_id"`
	LeagueSeasonName string    `json:"league_season_name" db:"league_season_name"`
	Name             string    `json:"name" db:"name"`
	Created          time.Time `json:"created" db:"created"`
}

func SelectGroupByID

func SelectGroupByID(id int64) (*GROUP, error)

func SelectGroupByLeagueIDAndLeagueSeasonNameAndName

func SelectGroupByLeagueIDAndLeagueSeasonNameAndName(league_id int64, league_season_name string, name string) (*GROUP, error)

type GROUP_USER

type GROUP_USER struct {
	GroupID int64 `json:"group_id" db:"group_id"`
	UserID  int64 `json:"user_id" db:"user_id"`
}

type LEAGUE

type LEAGUE struct {
	ID             int64     `json:"id" db:"id"`
	PlatformEloID  int64     `json:"platform_elo_id" db:"platform_elo_id"`
	Name           string    `json:"name" db:"name"`
	GroupsLimit    int       `json:"groups_limit" db:"groups_limit"`
	GroupSizeLimit int       `json:"group_size_limit" db:"group_size_limit"`
	Start          time.Time `json:"start" db:"start"`
	End            time.Time `json:"end" db:"end"`
}

func SelectLeague

func SelectLeague(id int64) (*LEAGUE, error)

func SelectLeagueByPlatformEloIDAndName

func SelectLeagueByPlatformEloIDAndName(platform_elo_id int64, name string) (*LEAGUE, error)

type LEAGUE_SEASON

type LEAGUE_SEASON struct {
	LeagueID int64     `json:"league_id" db:"league_id"`
	Name     string    `json:"name" db:"name"`
	Start    time.Time `json:"start" db:"start"`
	End      time.Time `json:"end" db:"end"`
}

func SelectLeagueSeason

func SelectLeagueSeason(league_id int64, name string) (*LEAGUE_SEASON, error)

type PLATFORM

type PLATFORM struct {
	ID      int64  `json:"id" db:"id"`
	Name    string `json:"name" db:"name"`
	Version string `json:"version" db:"version"`
}

func SelectPlatform

func SelectPlatform(id int64) (*PLATFORM, error)

type PLATFORM_AUTH

type PLATFORM_AUTH struct {
	PlatformID int64 `json:"platform_id" db:"platform_id"`
}

type PLATFORM_ELO

type PLATFORM_ELO struct {
	PlatformID int64 `json:"platform_id" db:"platform_id"`
}

type PLATFORM_ENDPOINT

type PLATFORM_ENDPOINT struct {
	PlatformID int64  `json:"platform_id" db:"platform_id"`
	Name       string `json:"name" db:"name"`
	Path       string `json:"path" db:"path"`
}

type PLATFORM_USER

type PLATFORM_USER struct {
	UserID          int64  `json:"user_id" db:"user_id"`
	PlatformID      int64  `json:"platform_id" db:"platform_id"`
	AccessToken     string `json:"access_token" db:"access_token"`
	VerificationKey string `json:"verification_key" db:"verification_key"`
}

type RESULT

type RESULT struct {
	ID            int64     `json:"id" db:"id"`
	GroupID       int64     `json:"group_id" db:"group_id"`
	ELOBefore     int       `json:"elo_before" db:"elo_before"`
	ELOAfter      int       `json:"elo_after" db:"elo_after"`
	ELODifference int       `json:"elo_difference" db:"elo_difference"`
	Outcome       string    `json:"outcome" db:"outcome"`
	Played        time.Time `json:"played" db:"played"`
}

func SelectResult

func SelectResult(id int64) (*RESULT, error)

func SelectResultLastByGroupId

func SelectResultLastByGroupId(id int64) (*RESULT, error)

func SelectResultLastPlayed

func SelectResultLastPlayed() (*RESULT, error)

type RESULT_PLATFORM_ELO

type RESULT_PLATFORM_ELO struct {
	ResultID        int64  `json:"result_id" db:"result_id"`
	PlatformEloID   int64  `json:"platform_elo_id" db:"platform_elo_id"`
	VerificationKey string `json:"verification_key" db:"verification_key"`
}

type USER

type USER struct {
	ID         int64     `json:"id" db:"id"`
	Name       string    `json:"name" db:"name"`
	Email      string    `json:"email" db:"email"`
	Registered time.Time `json:"registered" db:"registered"`
	LastOnline time.Time `json:"last_online" db:"last_online"`
}

func SelectUserByEmail

func SelectUserByEmail(email string) (*USER, error)

func SelectUserByID

func SelectUserByID(id int64) (*USER, error)

Jump to

Keyboard shortcuts

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