Documentation
¶
Overview ¶
Package models contains the database interaction model code
GENERATED BY GOSCHEMA. DO NOT EDIT.
Package models contains the database interaction model code ¶
GENERATED BY GOSCHEMA. DO NOT EDIT.
Package models contains the database interaction model code ¶
GENERATED BY GOSCHEMA. DO NOT EDIT.
Package models contains the database interaction model code ¶
GENERATED BY GOSCHEMA. DO NOT EDIT.
Package models contains the database interaction model code ¶
GENERATED BY GOSCHEMA. DO NOT EDIT.
Index ¶
- Variables
- func InsertManyConstructorChampionships(db DB, ms ...*ConstructorChampionship) error
- func InsertManyDriverChampionships(db DB, ms ...*DriverChampionship) error
- func InsertManyRaceResults(db DB, ms ...*RaceResult) error
- func InsertManyRaces(db DB, ms ...*Race) error
- func InsertManySeasons(db DB, ms ...*Season) error
- func IsKeySet(x interface{}) bool
- type ConstructorChampionship
- func (m *ConstructorChampionship) Delete(db DB) error
- func (m *ConstructorChampionship) GetSeasonIdSeason(db DB) (*Season, error)
- func (m *ConstructorChampionship) Insert(db DB) error
- func (m *ConstructorChampionship) InsertWithUpdate(db DB) error
- func (m *ConstructorChampionship) IsPrimaryKeySet() bool
- func (m *ConstructorChampionship) Patch(db DB, newT *ConstructorChampionship) error
- func (m *ConstructorChampionship) Save(db DB) error
- func (m *ConstructorChampionship) SaveOrUpdate(db DB) error
- func (m *ConstructorChampionship) Update(db DB) error
- type DB
- type DBTransactionHandler
- type DBTransactioner
- type Deletable
- type DriverChampionship
- func (m *DriverChampionship) Delete(db DB) error
- func (m *DriverChampionship) GetSeasonIdSeason(db DB) (*Season, error)
- func (m *DriverChampionship) Insert(db DB) error
- func (m *DriverChampionship) InsertWithUpdate(db DB) error
- func (m *DriverChampionship) IsPrimaryKeySet() bool
- func (m *DriverChampionship) Patch(db DB, newT *DriverChampionship) error
- func (m *DriverChampionship) Save(db DB) error
- func (m *DriverChampionship) SaveOrUpdate(db DB) error
- func (m *DriverChampionship) Update(db DB) error
- type LoggableDBTransactionHandler
- type PostDeletable
- type PostSaveable
- type PreDeletable
- type PreSaveable
- type Race
- func (m *Race) Delete(db DB) error
- func (m *Race) GetSeasonIdSeason(db DB) (*Season, error)
- func (m *Race) Insert(db DB) error
- func (m *Race) InsertWithUpdate(db DB) error
- func (m *Race) IsPrimaryKeySet() bool
- func (m *Race) Patch(db DB, newT *Race) error
- func (m *Race) Save(db DB) error
- func (m *Race) SaveOrUpdate(db DB) error
- func (m *Race) Update(db DB) error
- type RaceResult
- func (m *RaceResult) Delete(db DB) error
- func (m *RaceResult) GetRaceIdRace(db DB) (*Race, error)
- func (m *RaceResult) Insert(db DB) error
- func (m *RaceResult) InsertWithUpdate(db DB) error
- func (m *RaceResult) IsPrimaryKeySet() bool
- func (m *RaceResult) Patch(db DB, newT *RaceResult) error
- func (m *RaceResult) Save(db DB) error
- func (m *RaceResult) SaveOrUpdate(db DB) error
- func (m *RaceResult) Update(db DB) error
- type Saveable
- type Season
- func (m *Season) Delete(db DB) error
- func (m *Season) Insert(db DB) error
- func (m *Season) InsertWithUpdate(db DB) error
- func (m *Season) IsPrimaryKeySet() bool
- func (m *Season) Patch(db DB, newT *Season) error
- func (m *Season) Save(db DB) error
- func (m *Season) SaveOrUpdate(db DB) error
- func (m *Season) Update(db DB) error
- type SetLogger
- type TransactionFunc
- type TransactionHandler
- type Transactioner
- type XODB
Constants ¶
This section is empty.
Variables ¶
var DBLog = func(string, ...any) {}
DBLog provides the log func used by generated queries.
var DatabaseLatency = promauto.NewHistogramVec( prometheus.HistogramOpts{ Name: "database_latency", Help: "Duration of database queries", }, []string{"query"}, )
DatabaseLatency is the duration of database queries.
var ErrConstraintViolation = errors.New("constraint violation")
ErrConstraintViolation is returned if a constraint is violated
var ErrDuplicate = errors.New("duplicate entry")
ErrDuplicate is returned if a duplicate entry is found
var ErrNoAffectedRows = errors.New("no affected rows")
ErrNoAffectedRows is returned if a model update affected no rows
var XOLog = func(msg string, args ...any) { DBLog(msg, args...) }
XOLog is a compat shim for DBLog
Functions ¶
func InsertManyConstructorChampionships ¶
func InsertManyConstructorChampionships(db DB, ms ...*ConstructorChampionship) error
func InsertManyDriverChampionships ¶
func InsertManyDriverChampionships(db DB, ms ...*DriverChampionship) error
func InsertManyRaceResults ¶
func InsertManyRaceResults(db DB, ms ...*RaceResult) error
func InsertManyRaces ¶
func InsertManySeasons ¶
Types ¶
type ConstructorChampionship ¶
type ConstructorChampionship struct {
Id int `db:"id,pk,autoinc"`
SeasonId int `db:"season_id"`
Position int `db:"position"`
Name string `db:"name"`
Points float64 `db:"points"`
UpdatedAt time.Time `db:"updated_at"`
}
ConstructorChampionship represents a row from 'constructor_championship'.
func ConstructorChampionshipById ¶
func ConstructorChampionshipById(db DB, id int) (*ConstructorChampionship, error)
ConstructorChampionshipById retrieves a row from 'constructor_championship' as a ConstructorChampionship.
Generated from primary key.
func (*ConstructorChampionship) Delete ¶
func (m *ConstructorChampionship) Delete(db DB) error
Delete deletes the ConstructorChampionship from the database.
func (*ConstructorChampionship) GetSeasonIdSeason ¶
func (m *ConstructorChampionship) GetSeasonIdSeason(db DB) (*Season, error)
GetSeasonIdSeason Gets an instance of Season
Generated from constraint team_championship_season_id_fk
func (*ConstructorChampionship) Insert ¶
func (m *ConstructorChampionship) Insert(db DB) error
Insert inserts the ConstructorChampionship to the database.
func (*ConstructorChampionship) InsertWithUpdate ¶
func (m *ConstructorChampionship) InsertWithUpdate(db DB) error
InsertWithUpdate inserts the ConstructorChampionship to the database, and tries to update on unique constraint violations.
func (*ConstructorChampionship) IsPrimaryKeySet ¶
func (m *ConstructorChampionship) IsPrimaryKeySet() bool
IsPrimaryKeySet returns true if all primary key fields are set to none zero values
func (*ConstructorChampionship) Patch ¶
func (m *ConstructorChampionship) Patch(db DB, newT *ConstructorChampionship) error
func (*ConstructorChampionship) Save ¶
func (m *ConstructorChampionship) Save(db DB) error
Save saves the ConstructorChampionship to the database.
func (*ConstructorChampionship) SaveOrUpdate ¶
func (m *ConstructorChampionship) SaveOrUpdate(db DB) error
SaveOrUpdate saves the ConstructorChampionship to the database, but tries to update on unique constraint violations.
func (*ConstructorChampionship) Update ¶
func (m *ConstructorChampionship) Update(db DB) error
Update updates the ConstructorChampionship in the database.
type DB ¶
type DB interface {
Exec(string, ...any) (sql.Result, error)
Query(string, ...any) (*sql.Rows, error)
QueryRow(string, ...any) *sql.Row
// Additional sqlx methods we like
Get(dest any, query string, args ...interface{}) error
Select(dest any, query string, args ...interface{}) error
}
DB is the common interface for database operations
This should work with database/sql.DB and database/sql.Tx.
type DBTransactionHandler ¶
type DBTransactionHandler struct {
// contains filtered or unexported fields
}
DBTransactionHandler handles a transaction that will return any error.
func NewDBTransactionHandler ¶
func NewDBTransactionHandler(db Transactioner) *DBTransactionHandler
NewDBTransactionHandler returns a configured instance of DBTransactionHandler
func (*DBTransactionHandler) Handle ¶
func (th *DBTransactionHandler) Handle(f TransactionFunc) error
Handle implements the TransactionHandler interface.
type DBTransactioner ¶
type DBTransactioner interface {
DB
Transactioner
}
DBTransactioner is the interface that database connections that can utilise transactions should implement.
type Deletable ¶
Deletable is the interface implemented by types which can delete themselves from the database.
type DriverChampionship ¶
type DriverChampionship struct {
Id int `db:"id,pk,autoinc"`
SeasonId int `db:"season_id"`
Position int `db:"position"`
Driver string `db:"driver"`
DriverTag string `db:"driver_tag"`
Nationality string `db:"nationality"`
Team string `db:"team"`
Points float64 `db:"points"`
UpdatedAt time.Time `db:"updated_at"`
}
DriverChampionship represents a row from 'driver_championship'.
func DriverChampionshipById ¶
func DriverChampionshipById(db DB, id int) (*DriverChampionship, error)
DriverChampionshipById retrieves a row from 'driver_championship' as a DriverChampionship.
Generated from primary key.
func (*DriverChampionship) Delete ¶
func (m *DriverChampionship) Delete(db DB) error
Delete deletes the DriverChampionship from the database.
func (*DriverChampionship) GetSeasonIdSeason ¶
func (m *DriverChampionship) GetSeasonIdSeason(db DB) (*Season, error)
GetSeasonIdSeason Gets an instance of Season
Generated from constraint driver_championship_season_id_fk
func (*DriverChampionship) Insert ¶
func (m *DriverChampionship) Insert(db DB) error
Insert inserts the DriverChampionship to the database.
func (*DriverChampionship) InsertWithUpdate ¶
func (m *DriverChampionship) InsertWithUpdate(db DB) error
InsertWithUpdate inserts the DriverChampionship to the database, and tries to update on unique constraint violations.
func (*DriverChampionship) IsPrimaryKeySet ¶
func (m *DriverChampionship) IsPrimaryKeySet() bool
IsPrimaryKeySet returns true if all primary key fields are set to none zero values
func (*DriverChampionship) Patch ¶
func (m *DriverChampionship) Patch(db DB, newT *DriverChampionship) error
func (*DriverChampionship) Save ¶
func (m *DriverChampionship) Save(db DB) error
Save saves the DriverChampionship to the database.
func (*DriverChampionship) SaveOrUpdate ¶
func (m *DriverChampionship) SaveOrUpdate(db DB) error
SaveOrUpdate saves the DriverChampionship to the database, but tries to update on unique constraint violations.
func (*DriverChampionship) Update ¶
func (m *DriverChampionship) Update(db DB) error
Update updates the DriverChampionship in the database.
type LoggableDBTransactionHandler ¶
type LoggableDBTransactionHandler struct {
// contains filtered or unexported fields
}
LoggableDBTransactionHandler handles a transaction and logs any error.
func NewLoggableDBTransactionHandler ¶
func NewLoggableDBTransactionHandler(db Transactioner, l *slog.Logger) *LoggableDBTransactionHandler
NewLoggableDBTransactionHandler returns a configured instance of LoggableDBTransactionHandler
type PostDeletable ¶
type PostDeletable interface {
PostDelete() error
}
PostDeletable is the interface implemented by types which run a post delete step.
type PostSaveable ¶
type PostSaveable interface {
PostSave() error
}
PostSaveable is the interface implemented by types which run a post save step.
type PreDeletable ¶
type PreDeletable interface {
PreDelete() error
}
PreDeletable is the interface implemented by types which run a pre delete step.
type PreSaveable ¶
PreSaveable is the interface implemented by types which run a pre save step.
type Race ¶
type Race struct {
Id int `db:"id,pk,autoinc"`
SeasonId int `db:"season_id"`
GrandPrix string `db:"grand_prix"`
Date time.Time `db:"date"`
UpdatedAt time.Time `db:"updated_at"`
}
Race represents a row from 'race'.
func (*Race) GetSeasonIdSeason ¶
GetSeasonIdSeason Gets an instance of Season
Generated from constraint race_season_id_fk
func (*Race) InsertWithUpdate ¶
InsertWithUpdate inserts the Race to the database, and tries to update on unique constraint violations.
func (*Race) IsPrimaryKeySet ¶
IsPrimaryKeySet returns true if all primary key fields are set to none zero values
func (*Race) SaveOrUpdate ¶
SaveOrUpdate saves the Race to the database, but tries to update on unique constraint violations.
type RaceResult ¶
type RaceResult struct {
Id int `db:"id,pk,autoinc"`
RaceId int `db:"race_id"`
Position string `db:"position"`
DriverNumber int `db:"driver_number"`
Driver string `db:"driver"`
DriverTag string `db:"driver_tag"`
Team string `db:"team"`
Laps int `db:"laps"`
TimeRetired string `db:"time_retired"`
Points float64 `db:"points"`
UpdatedAt time.Time `db:"updated_at"`
}
RaceResult represents a row from 'race_result'.
func RaceResultById ¶
func RaceResultById(db DB, id int) (*RaceResult, error)
RaceResultById retrieves a row from 'race_result' as a RaceResult.
Generated from primary key.
func (*RaceResult) Delete ¶
func (m *RaceResult) Delete(db DB) error
Delete deletes the RaceResult from the database.
func (*RaceResult) GetRaceIdRace ¶
func (m *RaceResult) GetRaceIdRace(db DB) (*Race, error)
GetRaceIdRace Gets an instance of Race
Generated from constraint race_result_race_id_fk
func (*RaceResult) Insert ¶
func (m *RaceResult) Insert(db DB) error
Insert inserts the RaceResult to the database.
func (*RaceResult) InsertWithUpdate ¶
func (m *RaceResult) InsertWithUpdate(db DB) error
InsertWithUpdate inserts the RaceResult to the database, and tries to update on unique constraint violations.
func (*RaceResult) IsPrimaryKeySet ¶
func (m *RaceResult) IsPrimaryKeySet() bool
IsPrimaryKeySet returns true if all primary key fields are set to none zero values
func (*RaceResult) Patch ¶
func (m *RaceResult) Patch(db DB, newT *RaceResult) error
func (*RaceResult) Save ¶
func (m *RaceResult) Save(db DB) error
Save saves the RaceResult to the database.
func (*RaceResult) SaveOrUpdate ¶
func (m *RaceResult) SaveOrUpdate(db DB) error
SaveOrUpdate saves the RaceResult to the database, but tries to update on unique constraint violations.
func (*RaceResult) Update ¶
func (m *RaceResult) Update(db DB) error
Update updates the RaceResult in the database.
type Saveable ¶
Saveable is the interface implemented by types which can save themselves to the database.
type Season ¶
Season represents a row from 'season'.
func (*Season) InsertWithUpdate ¶
InsertWithUpdate inserts the Season to the database, and tries to update on unique constraint violations.
func (*Season) IsPrimaryKeySet ¶
IsPrimaryKeySet returns true if all primary key fields are set to none zero values
func (*Season) SaveOrUpdate ¶
SaveOrUpdate saves the Season to the database, but tries to update on unique constraint violations.
type SetLogger ¶
SetLogger is the interface implemented by types which have the ability to configure their log entry.
type TransactionFunc ¶
TransactionFunc is a function to be called within a transaction.
type TransactionHandler ¶
type TransactionHandler interface {
Handle(TransactionFunc) error
}
type Transactioner ¶
Transactioner is the interface that a database connection that can start a transaction should implement.