Documentation ¶
Index ¶
- type EnumRecord
- func (EnumRecord[T]) Columns() []string
- func (record EnumRecord[T]) NamedValues() ([]driver.NamedValue, error)
- func (EnumRecord[T]) ScanRow(row *sql.Row) error
- func (EnumRecord[T]) ScanValues(...driver.Value) error
- func (EnumRecord[T]) Scannables() []any
- func (record EnumRecord[T]) Values() ([]any, error)
- type EnumTable
- func (table EnumTable) Columns() []string
- func (table EnumTable[T]) Get(id uint64) (T, error)
- func (table EnumTable) GetByName(name string) (T, error)
- func (table EnumTable[T]) GetNamed(name string) (T, error)
- func (table EnumTable[T]) Insert(record *T) error
- func (table EnumTable) Name() string
- func (table EnumTable[T]) NewRecord() EnumRecord[T]
- func (table EnumTable[T]) SelectAll() (chan<- T, error)
- func (table EnumTable[T]) SqlCreate() string
- func (table EnumTable[T]) SqlInit() string
- func (table EnumTable[T]) Strings() []string
- func (table EnumTable[T]) Values() []T
- type LegacyMapRecord
- func (LegacyMapRecord) Columns() []string
- func (record LegacyMapRecord) NamedValues() ([]driver.NamedValue, error)
- func (record *LegacyMapRecord) ScanRow(row *sql.Row) error
- func (record *LegacyMapRecord) ScanValues(values ...driver.Value) error
- func (record *LegacyMapRecord) Scannables() []any
- func (record LegacyMapRecord) Values() ([]any, error)
- type LegacyMatchRecord
- func (*LegacyMatchRecord) Columns() []string
- func (record *LegacyMatchRecord) NamedValues() ([]driver.NamedValue, error)
- func (record *LegacyMatchRecord) ScanRow(row *sql.Row) error
- func (record *LegacyMatchRecord) ScanValues(values ...driver.Value) error
- func (record *LegacyMatchRecord) Scannables() []any
- func (record *LegacyMatchRecord) Values() ([]any, error)
- type MutableTable
- type OsnDB
- type PlayerRecord
- func (player *PlayerRecord) Columns() []string
- func (player *PlayerRecord) NamedValues() ([]driver.NamedValue, error)
- func (player *PlayerRecord) ScanRow(row *sql.Row) error
- func (player *PlayerRecord) ScanValues(values ...driver.Value) error
- func (player *PlayerRecord) Scannables() []any
- func (player *PlayerRecord) Values() ([]any, error)
- type PlayerRoleRecord
- func (*PlayerRoleRecord) Columns() []string
- func (record *PlayerRoleRecord) NamedValues() ([]driver.NamedValue, error)
- func (record *PlayerRoleRecord) ScanRow(row *sql.Row) error
- func (record *PlayerRoleRecord) ScanValues(values ...driver.Value) error
- func (record *PlayerRoleRecord) Scannables() []any
- func (record *PlayerRoleRecord) Values() ([]any, error)
- type Record
- type StandingsRecord
- func (*StandingsRecord) Columns() []string
- func (record *StandingsRecord) NamedValues() ([]driver.NamedValue, error)
- func (record *StandingsRecord) ScanRow(row *sql.Row) error
- func (record *StandingsRecord) ScanValues(values ...driver.Value) error
- func (record *StandingsRecord) Scannables() []any
- func (record *StandingsRecord) Values() ([]any, error)
- type Table
- type TableSql
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EnumRecord ¶
The record abstraction for enums is interesting because it is both a single enum value (a one-byte int) and the unique (id, name) row in its backing database table.
func (EnumRecord[T]) Columns ¶
func (EnumRecord[T]) Columns() []string
func (EnumRecord[T]) NamedValues ¶
func (record EnumRecord[T]) NamedValues() ([]driver.NamedValue, error)
func (EnumRecord[T]) ScanValues ¶
func (EnumRecord[T]) ScanValues(...driver.Value) error
func (EnumRecord[T]) Scannables ¶
func (EnumRecord[T]) Scannables() []any
func (EnumRecord[T]) Values ¶
func (record EnumRecord[T]) Values() ([]any, error)
type EnumTable ¶
Serialized enum types are a recurring pattern in fully defined relational DBs and here we make the simplifying assumption that any enumerated type can fit inside a single byte. If the domain is larger than 255 items, express that relation as a [Table[T Record]], named by a [TableIndex[Record, comparable]].
func MakeEnumTable ¶
Constructor function for making an enum table with the indicated values.
func (EnumTable[T]) Get ¶
Basic getter is equivalent to T(id) but this also validates. Included to conform with the [Table[T]] interface.
func (EnumTable[T]) GetNamed ¶
Returns an EnumRecord[T] instance that matches the provided name. If there is no value T with that name, it returns the zero (assumed UNKNOWN) value. Unlike the query-backed getter for [Table[T]], this never returns an error.
func (EnumTable[T]) Insert ¶
EnumTable does not allow insertions, but it provides the method to match [Table[T]].
func (EnumTable[T]) NewRecord ¶
func (table EnumTable[T]) NewRecord() EnumRecord[T]
type LegacyMapRecord ¶
func NewMapRecord ¶
func NewMapRecord() *LegacyMapRecord
func (LegacyMapRecord) Columns ¶
func (LegacyMapRecord) Columns() []string
func (LegacyMapRecord) NamedValues ¶
func (record LegacyMapRecord) NamedValues() ([]driver.NamedValue, error)
func (*LegacyMapRecord) ScanValues ¶
func (record *LegacyMapRecord) ScanValues(values ...driver.Value) error
func (*LegacyMapRecord) Scannables ¶
func (record *LegacyMapRecord) Scannables() []any
This is provided for completeness but it has a flaw in that the details are not recoverable. However, at present this method is only called from the `SELECT * FROM maps;` path, so it actually works out to get an abbreviation.
func (LegacyMapRecord) Values ¶
func (record LegacyMapRecord) Values() ([]any, error)
type LegacyMatchRecord ¶
type LegacyMatchRecord struct { // Embedded so that type inference on Table[*LegacyMatchRecord] works. osn.LegacyMatch }
func MakeMatchRecord ¶
func MakeMatchRecord(match osn.LegacyMatch) *LegacyMatchRecord
Constructs a LegacyMatchRecord from an osn.LegacyMatch which it encapsulates.
func NewMatchRecord ¶
func NewMatchRecord() *LegacyMatchRecord
Returns a zero record for populating with match metadata.
func (*LegacyMatchRecord) Columns ¶
func (*LegacyMatchRecord) Columns() []string
func (*LegacyMatchRecord) NamedValues ¶
func (record *LegacyMatchRecord) NamedValues() ([]driver.NamedValue, error)
func (*LegacyMatchRecord) ScanValues ¶
func (record *LegacyMatchRecord) ScanValues(values ...driver.Value) error
func (*LegacyMatchRecord) Scannables ¶
func (record *LegacyMatchRecord) Scannables() []any
func (*LegacyMatchRecord) Values ¶
func (record *LegacyMatchRecord) Values() ([]any, error)
type MutableTable ¶
Variant on the table type which allows for inserting and deleting records.
func MakeMatchesTable ¶
func MakeMatchesTable(sqldb *sql.DB) MutableTable[*LegacyMatchRecord]
func MakePlayersTable ¶
func MakePlayersTable(sqldb *sql.DB) MutableTable[*PlayerRecord]
func MakeRolesTable ¶
func MakeRolesTable(sqldb *sql.DB) MutableTable[*PlayerRoleRecord]
func MakeStandingsTable ¶
func MakeStandingsTable(sqldb *sql.DB) MutableTable[*StandingsRecord]
type OsnDB ¶
type OsnDB interface { MustCreateAndPopulateTables() // Create tables or die trying. Close() // Closes the database and attached resources. MapByID(id uint8) (osn.LegacyMap, error) MapByName(name string) (osn.LegacyMap, error) Players() MutableTable[*PlayerRecord] Matches() MutableTable[*LegacyMatchRecord] Standings() MutableTable[*StandingsRecord] UpdateMatchStatus(osn.GameID, osn.FetchStatus) error }
Interface for simplifying the interaction with a backing database.
DB includes match metadata, map identities, player history and replay index.
type PlayerRecord ¶
type PlayerRecord struct { // For it to be a pointer-receiver in the following methods, it needs to be an // embedded struct member rather than a simple alias type. osn.Player }
This satisfies the Record interface for use as Table[*Record] while being only a thin wrapper around the Player struct.
func NewPlayerRecord ¶
func NewPlayerRecord() *PlayerRecord
func (*PlayerRecord) Columns ¶
func (player *PlayerRecord) Columns() []string
func (*PlayerRecord) NamedValues ¶
func (player *PlayerRecord) NamedValues() ([]driver.NamedValue, error)
func (*PlayerRecord) ScanValues ¶
func (player *PlayerRecord) ScanValues(values ...driver.Value) error
func (*PlayerRecord) Scannables ¶
func (player *PlayerRecord) Scannables() []any
func (*PlayerRecord) Values ¶
func (player *PlayerRecord) Values() ([]any, error)
type PlayerRoleRecord ¶
type PlayerRoleRecord struct { MatchID int64 PlayerID int64 TurnOrder osn.PlayerColorEnum }
Relation for which players are participating in which matches, and the turn order they are assigned to. Appropriate for both 1v1 and 2v2 matches.
func NewRoleRecord ¶
func NewRoleRecord() *PlayerRoleRecord
func (*PlayerRoleRecord) Columns ¶
func (*PlayerRoleRecord) Columns() []string
func (*PlayerRoleRecord) NamedValues ¶
func (record *PlayerRoleRecord) NamedValues() ([]driver.NamedValue, error)
func (*PlayerRoleRecord) ScanValues ¶
func (record *PlayerRoleRecord) ScanValues(values ...driver.Value) error
func (*PlayerRoleRecord) Scannables ¶
func (record *PlayerRoleRecord) Scannables() []any
func (*PlayerRoleRecord) Values ¶
func (record *PlayerRoleRecord) Values() ([]any, error)
type Record ¶
type Record interface { Columns() []string Values() ([]any, error) NamedValues() ([]driver.NamedValue, error) ScanValues(...driver.Value) error ScanRow(*sql.Row) error Scannables() []any }
Abstraction over the structural type of values in a table or group of tables.
type StandingsRecord ¶
type StandingsRecord struct { After int64 Until int64 osn.PlayerStanding }
func NewStandingsRecord ¶
func NewStandingsRecord() *StandingsRecord
func (*StandingsRecord) Columns ¶
func (*StandingsRecord) Columns() []string
func (*StandingsRecord) NamedValues ¶
func (record *StandingsRecord) NamedValues() ([]driver.NamedValue, error)
func (*StandingsRecord) ScanValues ¶
func (record *StandingsRecord) ScanValues(values ...driver.Value) error
func (*StandingsRecord) Scannables ¶
func (record *StandingsRecord) Scannables() []any
func (*StandingsRecord) Values ¶
func (record *StandingsRecord) Values() ([]any, error)
type Table ¶
type Table[T Record] interface { TableSql NewRecord() T Get(int64) (T, error) GetByName(string) (T, error) SelectAll() (<-chan T, error) }
Common interface for one or more database tables and retrieval of records.
func MakeMapsTable ¶
func MakeMapsTable(sqldb *sql.DB) Table[*LegacyMapRecord]