Documentation
¶
Overview ¶
Package database provides interfaces for database connection and repositories for various entities.
Index ¶
- Variables
- func IDsToString[I ID](ids []I) []string
- func IsInternal(err error) bool
- func IsNotFound(err error) bool
- func NewInternalError(err error) error
- func NewNotFoundError(err error) error
- func SetConnection(ctx context.Context, repositoryConnector RepositoryConnector) context.Context
- func SetConnectionForGinContext(c *gin.Context, repositoryConnector RepositoryConnector)
- type DBConnector
- type DBConnectorWithTx
- type GameServer
- type GameServersRepository
- type ID
- type MapStat
- type MapStatRepository
- type Match
- type MatchesRepository
- type Player
- type PlayerStat
- type PlayerStatRepository
- type PlayersRepository
- type RepositoryConnector
- type RepositoryConnectorWithTx
- type Team
- type TeamsRepository
- type User
- type UsersRepositry
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotFound = errors.New("specified resource not found") ErrInternal = errors.New("internal error") )
var (
// RepositoryConnectorKey is a key to store repositoryConnector in gin.Context.
RepositoryConnectorKey = "repositoryConnector"
)
Functions ¶
func IDsToString ¶
func IsInternal ¶
func IsNotFound ¶
func NewInternalError ¶
func NewNotFoundError ¶
func SetConnection ¶
func SetConnection(ctx context.Context, repositoryConnector RepositoryConnector) context.Context
func SetConnectionForGinContext ¶
func SetConnectionForGinContext(c *gin.Context, repositoryConnector RepositoryConnector)
SetConnectionForGinContext gin.ContextにRepositoryConnectorを設定する
Types ¶
type DBConnector ¶
type DBConnector interface { // Open opens a database connection. // You must call Close after using the database. Open() error // GetConnection returns a opened database connection. Potentially returns nil. GetConnection() *sql.DB // Close closes a database connection. Close() error }
DBConnector is a database connection initiator.
type DBConnectorWithTx ¶
type DBConnectorWithTx interface { // Open opens a database connection. // You must call Close after using the database. Open() error // GetConnection returns a opened database connection. Potentially returns nil. GetConnection() *sql.DB // Close closes a database connection. Close() error // BeginTx starts a transaction. BeginTx() error // GetTx returns a transaction. Potentially returns nil. GetTx() *sql.Tx // Commit commits a transaction. Commit() error // Rollback rollbacks a transaction. Rollback() error }
DBConnectorWithTx is a database connection initiator with transaction.
type GameServer ¶
type GameServersRepository ¶
type GameServersRepository interface { // AddGameServer adds a game server. AddGameServer(ctx context.Context, userID entity.UserID, ip string, port uint32, rconPassword string, displayName string, isPublic bool) (entity.GameServerID, error) // GetGameServer returns a game server. GetGameServer(ctx context.Context, id entity.GameServerID) (*GameServer, error) // GetPublicGameServers returns public game servers. GetPublicGameServers(ctx context.Context) ([]*GameServer, error) // GetGameServersByUser returns game servers owned by a user. GetGameServersByUser(ctx context.Context, userID entity.UserID) ([]*GameServer, error) // GetGameServersByUsers returns game servers owned by users. GetGameServersByUsers(ctx context.Context, userIDs []entity.UserID) (map[entity.UserID][]*GameServer, error) // DeleteGameServer deletes a game server. DeleteGameServer(ctx context.Context, id entity.GameServerID) error }
GameServersRepository is an interface for game server repository.
type MapStatRepository ¶
type MapStatRepository interface { // TODO. // AddMapStats(ctx context.Context, matchID int64, mapNumber uint32, mapName string, winnerID int64, team1Score uint32, team2Score uint32) (*entity.MapStats, error) // GetMapStats returns map stats. GetMapStat(ctx context.Context, id entity.MapStatsID) (*MapStat, error) // GetMapStatsByMatch returns map stats owned by a match. GetMapStatsByMatch(ctx context.Context, matchID entity.MatchID) ([]*MapStat, error) // BatchGetMapStatsByMatches returns map stats owned by matches. GetMapStatsByMatches(ctx context.Context, matchIDs []entity.MatchID) (map[entity.MatchID][]*MapStat, error) // GetMapStatsByMatchAndMap returns map stats owned by a match and map number. GetMapStatsByMatchAndMap(ctx context.Context, matchID entity.MatchID, mapNumber uint32) (*MapStat, error) }
MapStatRepository is an interface for map stats repository.
type Match ¶
type Match struct { ID entity.MatchID UserID entity.UserID ServerID entity.GameServerID Team1ID entity.TeamID Team2ID entity.TeamID Winner entity.TeamID StartTime *time.Time EndTime *time.Time MaxMaps int32 Title string SkipVeto bool APIKey string Team1Score uint32 Team2Score uint32 Forfeit *bool Status entity.MATCH_STATUS }
type MatchesRepository ¶
type MatchesRepository interface { // AddMatch adds a match. AddMatch(ctx context.Context, userID entity.UserID, serverID entity.GameServerID, team1ID entity.TeamID, team2ID entity.TeamID, maxMaps int32, title string, skipVeto bool, apiKey string) (entity.MatchID, error) // GetMatch returns a match. GetMatch(ctx context.Context, id entity.MatchID) (*Match, error) // GetMatchesByUser returns matches owned by a user. GetMatchesByUser(ctx context.Context, userID entity.UserID) ([]*Match, error) // GetMatchesByUsers returns matches owned by users. GetMatchesByUsers(ctx context.Context, userIDs []entity.UserID) (map[entity.UserID][]*Match, error) // GetMatchesByTeam returns matches owned by a team. GetMatchesByTeam(ctx context.Context, teamID entity.TeamID) ([]*Match, error) // GetMatchesByWinner returns matches won by a team. GetMatchesByWinner(ctx context.Context, teamID entity.TeamID) ([]*Match, error) // UpdateMatchWinner updates a match winner. UpdateMatchWinner(ctx context.Context, matchID entity.MatchID, winnerID entity.TeamID) error // UpdateTeam1Score updates a match team1 score. UpdateTeam1Score(ctx context.Context, matchID entity.MatchID, score uint32) error // UpdateTeam2Score updates a match team2 score. UpdateTeam2Score(ctx context.Context, matchID entity.MatchID, score uint32) error // CancelMatch cancels a match. CancelMatch(ctx context.Context, matchID entity.MatchID) error // StartMatch starts a match. StartMatch(ctx context.Context, matchID entity.MatchID) error }
MatchesRepository is an interface for match repository.
type PlayerStat ¶
type PlayerStat struct { ID entity.PlayerStatsID MatchID entity.MatchID MapID entity.MapStatsID TeamID entity.TeamID SteamID entity.SteamID Name string Kills int32 Assists int32 Deaths int32 RoundsPlayed uint32 FlashbangAssists uint32 Suicides uint32 HeadShotKills uint32 Damage uint32 BombPlants uint32 BombDefuses uint32 V1 uint32 V2 uint32 V3 uint32 V4 uint32 V5 uint32 K1 uint32 K2 uint32 K3 uint32 K4 uint32 K5 uint32 FirstDeathCT uint32 FirstDeathT uint32 FirstKillCT uint32 FirstKillT uint32 }
type PlayerStatRepository ¶
type PlayerStatRepository interface { // TODO. // AddPlayerStats(ctx context.Context, mapStatsID int64, steamID string, name string, teamID int64, kills uint32, assists uint32, deaths uint32, hs uint32, flashAssists uint32, kast float32, rating float32) (*entity.PlayerStats, error) // GetPlayerStatsBySteamID returns player stats owned by a steam ID. GetPlayerStatsBySteamID(ctx context.Context, steamID entity.SteamID) ([]*PlayerStat, error) // GetPlayerStatsByMatch returns player stats owned by a match. GetPlayerStatsByMatch(ctx context.Context, matchID entity.MatchID) ([]*PlayerStat, error) // GetPlayerStatsByMapstats returns player stats owned by a map stats. GetPlayerStatsByMapstats(ctx context.Context, mapStatsID []entity.MapStatsID) (map[entity.MapStatsID][]*PlayerStat, error) }
PlayerStatRepository is an interface for player stats repository.
type PlayersRepository ¶
type PlayersRepository interface { // AddPlayer adds a player. AddPlayer(ctx context.Context, teamID entity.TeamID, steamID entity.SteamID, name string) (entity.PlayerID, error) // GetPlayer returns a player. GetPlayer(ctx context.Context, id entity.PlayerID) (*Player, error) // GetPlayersByTeam returns players owned by a team. GetPlayersByTeam(ctx context.Context, teamID entity.TeamID) ([]*Player, error) // GetPlayersByTeams returns players owned by teams. GetPlayersByTeams(ctx context.Context, teamIDs []entity.TeamID) (map[entity.TeamID][]*Player, error) }
PlayersRepository is an interface for player repository.
type RepositoryConnector ¶
type RepositoryConnector interface { // Open opens a repository connection. You must call Close after using the repository. Open() error // Close closes a repository connection. Close() error // GetUserRepository returns a user repository. You must open a repository connection before calling this method. GetUserRepository() UsersRepositry // GetGameServersRepository returns a game server repository. You must open a repository connection before calling this method. GetGameServersRepository() GameServersRepository // GetMatchesRepository returns a match repository. You must open a repository connection before calling this method. GetMatchesRepository() MatchesRepository // GetMapStatRepository returns a map stats repository. You must open a repository connection before calling this method. GetMapStatRepository() MapStatRepository // GetPlayerStatRepository returns a player stats repository. You must open a repository connection before calling this method. GetPlayerStatRepository() PlayerStatRepository // GetTeamsRepository returns a team repository. You must open a repository connection before calling this method. GetTeamsRepository() TeamsRepository // GetPlayersRepository returns a player repository. You must open a repository connection before calling this method. GetPlayersRepository() PlayersRepository }
RepositoryConnector is a generic interface for opening and closing a repository connection.
func GetConnection ¶
func GetConnection(ctx context.Context) RepositoryConnector
func GetConnectionFromGinContext ¶
func GetConnectionFromGinContext(c *gin.Context) RepositoryConnector
GetConnectionFromGinContext gin.ContextからRepositoryConnectorを取得する
type RepositoryConnectorWithTx ¶
type RepositoryConnectorWithTx interface { // Open opens a repository connection. You must call Close after using the repository. // Transaction is started when Open is called. Open() error // Close closes a repository connection. Close() error // GetUserRepository returns a user repository. You must open a repository connection before calling this method. GetUserRepository() UsersRepositry // GetGameServersRepository returns a game server repository. You must open a repository connection before calling this method. GetGameServersRepository() GameServersRepository // GetMatchesRepository returns a match repository. You must open a repository connection before calling this method. GetMatchesRepository() MatchesRepository // GetMapStatRepository returns a map stats repository. You must open a repository connection before calling this method. GetMapStatRepository() MapStatRepository // GetPlayerStatRepository returns a player stats repository. You must open a repository connection before calling this method. GetPlayerStatRepository() PlayerStatRepository // GetTeamsRepository returns a team repository. You must open a repository connection before calling this method. GetTeamsRepository() TeamsRepository // GetPlayersRepository returns a player repository. You must open a repository connection before calling this method. GetPlayersRepository() PlayersRepository // Commit commits a transaction. Commit() error // Rollback rollbacks a transaction. Rollback() error }
RepositoryConnectorWithTx is a interface for opening and closing a repository connection with transaction.
type TeamsRepository ¶
type TeamsRepository interface { // AddTeam adds a team. AddTeam(ctx context.Context, userID entity.UserID, name string, tag string, flag string, logo string, public bool) (entity.TeamID, error) // GetTeam returns a team. GetTeam(ctx context.Context, id entity.TeamID) (*Team, error) // GetTeams returns teams. GetTeams(ctx context.Context, ids []entity.TeamID) ([]*Team, error) // GetTeamsByUser returns teams owned by a user. GetTeamsByUser(ctx context.Context, userID entity.UserID) ([]*Team, error) // GetTeamsByUsers returns teams owned by users. GetTeamsByUsers(ctx context.Context, userIDs []entity.UserID) (map[entity.UserID][]*Team, error) // GetPublicTeams returns public teams. GetPublicTeams(ctx context.Context) ([]*Team, error) }
TeamsRepository is an interface for team repository.
type UsersRepositry ¶
type UsersRepositry interface { // CreateUser creates a user. CreateUser(ctx context.Context, steamID entity.SteamID, name string, admin bool, hash []byte) (entity.UserID, error) // GetUser returns a user. GetUser(ctx context.Context, id entity.UserID) (*User, error) // GetUserBySteamID returns a user. GetUserBySteamID(ctx context.Context, steamID entity.SteamID) (*User, error) }
UsersRepositry is an interface for user repository.
Directories
¶
Path | Synopsis |
---|---|
Package mock_database is a generated GoMock package.
|
Package mock_database is a generated GoMock package. |
mysql
|
|