models

package
v0.0.0-...-e0b4b11 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2024 License: GPL-3.0 Imports: 10 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.

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 (
	HoleStatsFairwayHitHIT           = "HIT"
	HoleStatsFairwayHitLEFT          = "LEFT"
	HoleStatsFairwayHitRIGHT         = "RIGHT"
	HoleStatsFairwayHitSHORT         = "SHORT"
	HoleStatsFairwayHitLONG          = "LONG"
	HoleStatsFairwayHitNOTAPPLICABLE = "NOT_APPLICABLE"
)

Valid values for the 'FairwayHit' enum column

View Source
var (
	HoleStatsGreenHitHIT   = "HIT"
	HoleStatsGreenHitLEFT  = "LEFT"
	HoleStatsGreenHitRIGHT = "RIGHT"
	HoleStatsGreenHitSHORT = "SHORT"
	HoleStatsGreenHitLONG  = "LONG"
)

Valid values for the 'GreenHit' enum column

View Source
var (
	RoundHitStatsTypeGREEN   = "GREEN"
	RoundHitStatsTypeFAIRWAY = "FAIRWAY"
)

Valid values for the 'Type' enum column

View Source
var CourseColumns = []string{"Id", "Name", "RoundId"}

CourseColumns is the sorted column names for the type Course

View Source
var CourseDetailsColumns = []string{"BackNineMeters", "BackNinePar", "BackNineYards", "CourseId", "CourseRating", "FrontNineMeters", "FrontNinePar", "FrontNineYards", "Id", "Marker", "Slope", "TotalMeters", "TotalPar", "TotalYards"}

CourseDetailsColumns is the sorted column names for the type CourseDetails

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 HoleColumns = []string{"CourseDetailsId", "DistanceMeters", "DistanceYards", "Id", "Number", "Par", "Stroke"}

HoleColumns is the sorted column names for the type Hole

View Source
var HoleStatsColumns = []string{"FairwayHit", "GreenHit", "HoleId", "Id", "Penalties", "PinLocation", "Putts", "Score"}

HoleStatsColumns is the sorted column names for the type HoleStats

View Source
var RoundColumns = []string{"Id", "TeeTime", "UserId"}

RoundColumns is the sorted column names for the type Round

View Source
var RoundHitStatsColumns = []string{"Count", "Id", "Miss", "RoundStatsId", "Type"}

RoundHitStatsColumns is the sorted column names for the type RoundHitStats

View Source
var RoundStatsColumns = []string{"AvgFairwaysHit", "AvgGreensHit", "AvgPar3", "AvgPar4", "AvgPar5", "AvgPutts", "Id", "Penalties", "RoundId"}

RoundStatsColumns is the sorted column names for the type RoundStats

View Source
var UserColumns = []string{"Id", "LastLogin", "Name", "Password", "Username"}

UserColumns is the sorted column names for the type User

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

XOLog is a compat shim for DBLog

Functions

func InsertManyCourseDetailss

func InsertManyCourseDetailss(db DB, ms ...*CourseDetails) error

func InsertManyCourses

func InsertManyCourses(db DB, ms ...*Course) error

func InsertManyHoleStatss

func InsertManyHoleStatss(db DB, ms ...*HoleStats) error

func InsertManyHoles

func InsertManyHoles(db DB, ms ...*Hole) error

func InsertManyRoundHitStatss

func InsertManyRoundHitStatss(db DB, ms ...*RoundHitStats) error

func InsertManyRoundStatss

func InsertManyRoundStatss(db DB, ms ...*RoundStats) error

func InsertManyRounds

func InsertManyRounds(db DB, ms ...*Round) error

func InsertManyUsers

func InsertManyUsers(db DB, ms ...*User) 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 Course

type Course struct {
	Id      int    `db:"id,autoinc,pk"`
	RoundId int    `db:"round_id"`
	Name    string `db:"name"`
}

Course represents a row from 'course'.

func CourseById

func CourseById(db DB, id int) (*Course, error)

CourseById retrieves a row from 'course' as a Course.

Generated from primary key.

func (*Course) Delete

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

Delete deletes the Course from the database.

func (*Course) Insert

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

Insert inserts the Course to the database.

func (*Course) InsertWithUpdate

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

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

func (*Course) IsPrimaryKeySet

func (m *Course) IsPrimaryKeySet() bool

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

func (*Course) Save

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

Save saves the Course to the database.

func (*Course) SaveOrUpdate

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

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

func (*Course) Update

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

Update updates the Course in the database.

type CourseDetails

type CourseDetails struct {
	Id              int             `db:"id,autoinc,pk"`
	CourseId        int             `db:"course_id"`
	Marker          usql.NullString `db:"marker"`
	Slope           int             `db:"slope"`
	CourseRating    float64         `db:"course_rating"`
	FrontNinePar    int             `db:"front_nine_par"`
	BackNinePar     int             `db:"back_nine_par"`
	TotalPar        int             `db:"total_par"`
	FrontNineYards  int             `db:"front_nine_yards"`
	BackNineYards   int             `db:"back_nine_yards"`
	TotalYards      int             `db:"total_yards"`
	FrontNineMeters int             `db:"front_nine_meters"`
	BackNineMeters  int             `db:"back_nine_meters"`
	TotalMeters     int             `db:"total_meters"`
}

CourseDetails represents a row from 'course_details'.

func CourseDetailsById

func CourseDetailsById(db DB, id int) (*CourseDetails, error)

CourseDetailsById retrieves a row from 'course_details' as a CourseDetails.

Generated from primary key.

func (*CourseDetails) Delete

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

Delete deletes the CourseDetails from the database.

func (*CourseDetails) GetCourse

func (m *CourseDetails) GetCourse(db DB) (*Course, error)

GetCourse Gets an instance of Course

Generated from constraint course_details_course_id_fk

func (*CourseDetails) Insert

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

Insert inserts the CourseDetails to the database.

func (*CourseDetails) InsertWithUpdate

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

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

func (*CourseDetails) IsPrimaryKeySet

func (m *CourseDetails) IsPrimaryKeySet() bool

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

func (*CourseDetails) Save

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

Save saves the CourseDetails to the database.

func (*CourseDetails) SaveOrUpdate

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

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

func (*CourseDetails) Update

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

Update updates the CourseDetails 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 Hole

type Hole struct {
	Id              int `db:"id,autoinc,pk"`
	CourseDetailsId int `db:"course_details_id"`
	Number          int `db:"number"`
	Par             int `db:"par"`
	Stroke          int `db:"stroke"`
	DistanceYards   int `db:"distance_yards"`
	DistanceMeters  int `db:"distance_meters"`
}

Hole represents a row from 'hole'.

func HoleById

func HoleById(db DB, id int) (*Hole, error)

HoleById retrieves a row from 'hole' as a Hole.

Generated from primary key.

func (*Hole) Delete

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

Delete deletes the Hole from the database.

func (*Hole) GetCourseDetails

func (m *Hole) GetCourseDetails(db DB) (*CourseDetails, error)

GetCourseDetails Gets an instance of CourseDetails

Generated from constraint hole_course_details_id_fk

func (*Hole) Insert

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

Insert inserts the Hole to the database.

func (*Hole) InsertWithUpdate

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

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

func (*Hole) IsPrimaryKeySet

func (m *Hole) IsPrimaryKeySet() bool

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

func (*Hole) Save

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

Save saves the Hole to the database.

func (*Hole) SaveOrUpdate

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

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

func (*Hole) Update

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

Update updates the Hole in the database.

type HoleStats

type HoleStats struct {
	Id          int       `db:"id,autoinc,pk"`
	HoleId      int       `db:"hole_id"`
	Score       int       `db:"score"`
	FairwayHit  usql.Enum `db:"fairway_hit"`
	GreenHit    usql.Enum `db:"green_hit"`
	PinLocation string    `db:"pin_location"`
	Putts       int       `db:"putts"`
	Penalties   int       `db:"penalties"`
}

HoleStats represents a row from 'hole_stats'.

func HoleStatsById

func HoleStatsById(db DB, id int) (*HoleStats, error)

HoleStatsById retrieves a row from 'hole_stats' as a HoleStats.

Generated from primary key.

func (*HoleStats) Delete

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

Delete deletes the HoleStats from the database.

func (*HoleStats) GetHole

func (m *HoleStats) GetHole(db DB) (*Hole, error)

GetHole Gets an instance of Hole

Generated from constraint hole_stats_hole_id_fk

func (*HoleStats) Insert

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

Insert inserts the HoleStats to the database.

func (*HoleStats) InsertWithUpdate

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

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

func (*HoleStats) IsPrimaryKeySet

func (m *HoleStats) IsPrimaryKeySet() bool

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

func (*HoleStats) Save

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

Save saves the HoleStats to the database.

func (*HoleStats) SaveOrUpdate

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

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

func (*HoleStats) Update

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

Update updates the HoleStats 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 Round

type Round struct {
	Id      int       `db:"id,autoinc,pk"`
	UserId  int       `db:"user_id"`
	TeeTime time.Time `db:"tee_time"`
}

Round represents a row from 'round'.

func RoundById

func RoundById(db DB, id int) (*Round, error)

RoundById retrieves a row from 'round' as a Round.

Generated from primary key.

func (*Round) Delete

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

Delete deletes the Round from the database.

func (*Round) GetUser

func (m *Round) GetUser(db DB) (*User, error)

GetUser Gets an instance of User

Generated from constraint round_user_id_fk

func (*Round) Insert

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

Insert inserts the Round to the database.

func (*Round) InsertWithUpdate

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

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

func (*Round) IsPrimaryKeySet

func (m *Round) IsPrimaryKeySet() bool

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

func (*Round) Save

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

Save saves the Round to the database.

func (*Round) SaveOrUpdate

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

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

func (*Round) Update

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

Update updates the Round in the database.

type RoundHitStats

type RoundHitStats struct {
	Id           int       `db:"id,autoinc,pk"`
	RoundStatsId int       `db:"round_stats_id"`
	Type         usql.Enum `db:"type"`
	Miss         string    `db:"miss"`
	Count        int       `db:"count"`
}

RoundHitStats represents a row from 'round_hit_stats'.

func RoundHitStatsById

func RoundHitStatsById(db DB, id int) (*RoundHitStats, error)

RoundHitStatsById retrieves a row from 'round_hit_stats' as a RoundHitStats.

Generated from primary key.

func (*RoundHitStats) Delete

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

Delete deletes the RoundHitStats from the database.

func (*RoundHitStats) GetRoundStats

func (m *RoundHitStats) GetRoundStats(db DB) (*RoundStats, error)

GetRoundStats Gets an instance of RoundStats

Generated from constraint round_hit_stats_round_stats_id_fk

func (*RoundHitStats) Insert

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

Insert inserts the RoundHitStats to the database.

func (*RoundHitStats) InsertWithUpdate

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

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

func (*RoundHitStats) IsPrimaryKeySet

func (m *RoundHitStats) IsPrimaryKeySet() bool

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

func (*RoundHitStats) Save

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

Save saves the RoundHitStats to the database.

func (*RoundHitStats) SaveOrUpdate

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

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

func (*RoundHitStats) Update

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

Update updates the RoundHitStats in the database.

type RoundStats

type RoundStats struct {
	Id             int     `db:"id,autoinc,pk"`
	RoundId        int     `db:"round_id"`
	AvgFairwaysHit float64 `db:"avg_fairways_hit"`
	AvgGreensHit   float64 `db:"avg_greens_hit"`
	AvgPutts       float64 `db:"avg_putts"`
	Penalties      int     `db:"penalties"`
	AvgPar3        float64 `db:"avg_par_3"`
	AvgPar4        float64 `db:"avg_par_4"`
	AvgPar5        float64 `db:"avg_par_5"`
}

RoundStats represents a row from 'round_stats'.

func RoundStatsById

func RoundStatsById(db DB, id int) (*RoundStats, error)

RoundStatsById retrieves a row from 'round_stats' as a RoundStats.

Generated from primary key.

func (*RoundStats) Delete

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

Delete deletes the RoundStats from the database.

func (*RoundStats) GetRound

func (m *RoundStats) GetRound(db DB) (*Round, error)

GetRound Gets an instance of Round

Generated from constraint round_stats_round_id_fk

func (*RoundStats) Insert

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

Insert inserts the RoundStats to the database.

func (*RoundStats) InsertWithUpdate

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

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

func (*RoundStats) IsPrimaryKeySet

func (m *RoundStats) IsPrimaryKeySet() bool

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

func (*RoundStats) Save

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

Save saves the RoundStats to the database.

func (*RoundStats) SaveOrUpdate

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

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

func (*RoundStats) Update

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

Update updates the RoundStats 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 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 User

type User struct {
	Id        int           `db:"id,autoinc,pk"`
	Name      string        `db:"name"`
	Username  string        `db:"username"`
	Password  string        `db:"password"`
	LastLogin usql.NullTime `db:"last_login"`
}

User represents a row from 'user'.

func UserById

func UserById(db DB, id int) (*User, error)

UserById retrieves a row from 'user' as a User.

Generated from primary key.

func (*User) Delete

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

Delete deletes the User from the database.

func (*User) Insert

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

Insert inserts the User to the database.

func (*User) InsertWithUpdate

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

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

func (*User) IsPrimaryKeySet

func (m *User) IsPrimaryKeySet() bool

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

func (*User) Save

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

Save saves the User to the database.

func (*User) SaveOrUpdate

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

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

func (*User) Update

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

Update updates the User in the database.

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