Documentation
¶
Index ¶
- Variables
- func CloseDB() error
- func ConfigurePath()
- func ConfigurePathErr() error
- func EmptyCatalogue() error
- func GetDB() *gorm.DB
- func InitDB() error
- func PutInGame(id int, title, data string) error
- func Shutdown()
- func UpsertTokenRecord(token *Token) error
- type Game
- type GameRepository
- type Token
- type TokenRepository
Constants ¶
This section is empty.
Variables ¶
var ( Db *gorm.DB Path string )
Database variables
Functions ¶
func CloseDB ¶
func CloseDB() error
CloseDB closes the database connection. It returns an error if the database connection fails to close.
func ConfigurePath ¶ added in v0.4.2
func ConfigurePath()
ConfigurePath determines and sets the database path based on environment variables. It is public to allow for re-evaluation during testing.
func ConfigurePathErr ¶ added in v0.4.3
func ConfigurePathErr() error
ConfigurePathErr is like ConfigurePath but returns an error instead of calling log.Fatal.
func EmptyCatalogue ¶
func EmptyCatalogue() error
EmptyCatalogue removes all records from the game catalogue. It returns an error if the operation fails. Deprecated: Use GameRepository.Clear with context for better cancellation support.
func InitDB ¶
func InitDB() error
InitDB initializes the database and creates the tables if they don't exist. It returns an error if any step in the initialization process fails.
func PutInGame ¶
PutInGame inserts or updates a game record in the catalogue. It takes the game ID, title, and data as parameters and returns an error if the operation fails. Deprecated: Use GameRepository.Put with context for better cancellation support.
func Shutdown ¶ added in v0.4.3
func Shutdown()
Shutdown closes the database ignoring the error (for interrupt handling).
func UpsertTokenRecord ¶ added in v0.3.0
UpsertTokenRecord inserts or updates the token record in the database. Deprecated: Use TokenRepository.Upsert with context for better cancellation support.
Types ¶
type Game ¶
type Game struct {
ID int `gorm:"primaryKey" json:"id"`
Title string `gorm:"index" json:"title"` // Indexed for faster queries
Data string `json:"data"`
}
Game represents a game record in the catalogue.
func GetCatalogue ¶
GetCatalogue retrieves all games in the catalogue. It returns a slice of Game objects and an error if the operation fails. Deprecated: Use GameRepository.List with context for better cancellation support.
func GetGameByID ¶
GetGameByID retrieves a game from the catalogue by its ID. It takes the game ID as a parameter and returns a pointer to the Game object and an error if the operation fails. Deprecated: Use GameRepository.GetByID with context for better cancellation support.
func SearchGamesByName ¶
SearchGamesByName searches for games in the catalogue by name. It takes the game name as a parameter and returns a slice of Game objects and an error if the operation fails. Deprecated: Use GameRepository.SearchByTitle with context for better cancellation support.
type GameRepository ¶ added in v0.4.3
type GameRepository interface {
Put(ctx context.Context, g Game) error
GetByID(ctx context.Context, id int) (*Game, error)
List(ctx context.Context) ([]Game, error)
SearchByTitle(ctx context.Context, titleSubstr string) ([]Game, error)
Clear(ctx context.Context) error
}
GameRepository defines decoupled operations for game persistence.
func NewGameRepository ¶ added in v0.4.3
func NewGameRepository(db *gorm.DB) GameRepository
NewGameRepository creates a GameRepository. Accepts *gorm.DB to avoid global access.
type Token ¶ added in v0.3.0
type Token struct {
ID uint `gorm:"primaryKey;uniqueIndex"`
AccessToken string `json:"access_token,omitempty"`
RefreshToken string `json:"refresh_token,omitempty"`
ExpiresAt string `json:"expires_at,omitempty"`
}
Token represents the persisted auth tokens. Currently we enforce a single-row table by always upserting record with ID=1. A unique index on ID is implicit via primary key. Future multi-user support could drop this constraint and add a user scoping column.
func GetTokenRecord ¶ added in v0.3.0
GetTokenRecord retrieves the token record from the database. Deprecated: Use TokenRepository.Get with context for better cancellation support.
type TokenRepository ¶ added in v0.4.3
type TokenRepository interface {
Get(ctx context.Context) (*Token, error)
Upsert(ctx context.Context, token *Token) error
}
TokenRepository defines decoupled operations for token persistence.
func NewTokenRepository ¶ added in v0.4.3
func NewTokenRepository(db *gorm.DB) TokenRepository
NewTokenRepository creates a TokenRepository. Accepts *gorm.DB to avoid global access.