models

package
v0.0.0-...-51dc31f Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: GPL-3.0 Imports: 11 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
var DBLog = func(string, ...any) {}

DBLog provides the log func used by generated queries.

View Source
var DatabaseLatency = promauto.NewHistogramVec(
	prometheus.HistogramOpts{
		Name: "database_latency",
		Help: "Duration of database queries",
	},
	[]string{"query"},
)

DatabaseLatency is the duration of database queries.

View Source
var ErrConstraintViolation = errors.New("constraint violation")

ErrConstraintViolation is returned if a constraint is violated

View Source
var ErrDuplicate = errors.New("duplicate entry")

ErrDuplicate is returned if a duplicate entry is found

View Source
var ErrNoAffectedRows = errors.New("no affected rows")

ErrNoAffectedRows is returned if a model update affected no rows

View Source
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 InsertManyRaces(db DB, ms ...*Race) error

func InsertManySeasons

func InsertManySeasons(db DB, ms ...*Season) error

func IsKeySet

func IsKeySet(x interface{}) bool

IsKeySet returns true if 1. x is an integer and greater than zero. 2. x not an integer and is not the zero value. Otherwise, returns false

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 (*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

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

type Deletable interface {
	Delete(db DB) error
}

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

type PreSaveable interface {
	PreSave(db DB) error
}

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 RaceById

func RaceById(db DB, id int) (*Race, error)

RaceById retrieves a row from 'race' as a Race.

Generated from primary key.

func (*Race) Delete

func (m *Race) Delete(db DB) error

Delete deletes the Race from the database.

func (*Race) GetSeasonIdSeason

func (m *Race) GetSeasonIdSeason(db DB) (*Season, error)

GetSeasonIdSeason Gets an instance of Season

Generated from constraint race_season_id_fk

func (*Race) Insert

func (m *Race) Insert(db DB) error

Insert inserts the Race to the database.

func (*Race) InsertWithUpdate

func (m *Race) InsertWithUpdate(db DB) error

InsertWithUpdate inserts the Race to the database, and tries to update on unique constraint violations.

func (*Race) IsPrimaryKeySet

func (m *Race) IsPrimaryKeySet() bool

IsPrimaryKeySet returns true if all primary key fields are set to none zero values

func (*Race) Patch

func (m *Race) Patch(db DB, newT *Race) error

func (*Race) Save

func (m *Race) Save(db DB) error

Save saves the Race to the database.

func (*Race) SaveOrUpdate

func (m *Race) SaveOrUpdate(db DB) error

SaveOrUpdate saves the Race to the database, but tries to update on unique constraint violations.

func (*Race) Update

func (m *Race) Update(db DB) error

Update updates the Race in the database.

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

type Saveable interface {
	Save(db DB) error
}

Saveable is the interface implemented by types which can save themselves to the database.

type Season

type Season struct {
	Id   int `db:"id,pk,autoinc"`
	Year int `db:"year"`
}

Season represents a row from 'season'.

func SeasonById

func SeasonById(db DB, id int) (*Season, error)

SeasonById retrieves a row from 'season' as a Season.

Generated from primary key.

func (*Season) Delete

func (m *Season) Delete(db DB) error

Delete deletes the Season from the database.

func (*Season) Insert

func (m *Season) Insert(db DB) error

Insert inserts the Season to the database.

func (*Season) InsertWithUpdate

func (m *Season) InsertWithUpdate(db DB) error

InsertWithUpdate inserts the Season to the database, and tries to update on unique constraint violations.

func (*Season) IsPrimaryKeySet

func (m *Season) IsPrimaryKeySet() bool

IsPrimaryKeySet returns true if all primary key fields are set to none zero values

func (*Season) Patch

func (m *Season) Patch(db DB, newT *Season) error

func (*Season) Save

func (m *Season) Save(db DB) error

Save saves the Season to the database.

func (*Season) SaveOrUpdate

func (m *Season) SaveOrUpdate(db DB) error

SaveOrUpdate saves the Season to the database, but tries to update on unique constraint violations.

func (*Season) Update

func (m *Season) Update(db DB) error

Update updates the Season in the database.

type SetLogger

type SetLogger interface {
	SetLog(l *slog.Logger)
}

SetLogger is the interface implemented by types which have the ability to configure their log entry.

type TransactionFunc

type TransactionFunc func(db DB) error

TransactionFunc is a function to be called within a transaction.

type TransactionHandler

type TransactionHandler interface {
	Handle(TransactionFunc) error
}

type Transactioner

type Transactioner interface {
	Beginx() (*sqlx.Tx, error)
}

Transactioner is the interface that a database connection that can start a transaction should implement.

type XODB

type XODB = DB

XODB is a compat alias to DB

Jump to

Keyboard shortcuts

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