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
- Variables
- func InsertManyClubs(db DB, ms ...*Club) error
- func InsertManyCourseDetailss(db DB, ms ...*CourseDetails) error
- func InsertManyCourses(db DB, ms ...*Course) error
- func InsertManyHoles(db DB, ms ...*Hole) error
- func IsKeySet(x any) bool
- type Club
- func (m *Club) Delete(db DB) error
- func (m *Club) Insert(db DB) error
- func (m *Club) InsertClubWithPK(db DB) error
- func (m *Club) InsertWithUpdate(db DB) error
- func (m *Club) IsPrimaryKeySet() bool
- func (m *Club) Patch(db DB, newT *Club) error
- func (m *Club) Save(db DB) error
- func (m *Club) SaveOrUpdate(db DB) error
- func (m *Club) Update(db DB) error
- type Course
- func (m *Course) Delete(db DB) error
- func (m *Course) GetClubIdClub(db DB) (*Club, error)
- func (m *Course) Insert(db DB) error
- func (m *Course) InsertCourseWithPK(db DB) error
- func (m *Course) InsertWithUpdate(db DB) error
- func (m *Course) IsPrimaryKeySet() bool
- func (m *Course) Patch(db DB, newT *Course) error
- func (m *Course) Save(db DB) error
- func (m *Course) SaveOrUpdate(db DB) error
- func (m *Course) Update(db DB) error
- type CourseDetails
- func (m *CourseDetails) Delete(db DB) error
- func (m *CourseDetails) GetCourseIdCourse(db DB) (*Course, error)
- func (m *CourseDetails) Insert(db DB) error
- func (m *CourseDetails) InsertCourseDetailsWithPK(db DB) error
- func (m *CourseDetails) InsertWithUpdate(db DB) error
- func (m *CourseDetails) IsPrimaryKeySet() bool
- func (m *CourseDetails) Patch(db DB, newT *CourseDetails) error
- func (m *CourseDetails) Save(db DB) error
- func (m *CourseDetails) SaveOrUpdate(db DB) error
- func (m *CourseDetails) Update(db DB) error
- type DB
- type DBTransactionHandler
- type DBTransactioner
- type Deletable
- type Hole
- func (m *Hole) Delete(db DB) error
- func (m *Hole) GetDetailsIdCourseDetails(db DB) (*CourseDetails, error)
- func (m *Hole) Insert(db DB) error
- func (m *Hole) InsertHoleWithPK(db DB) error
- func (m *Hole) InsertWithUpdate(db DB) error
- func (m *Hole) IsPrimaryKeySet() bool
- func (m *Hole) Patch(db DB, newT *Hole) error
- func (m *Hole) Save(db DB) error
- func (m *Hole) SaveOrUpdate(db DB) error
- func (m *Hole) Update(db DB) error
- type LoggableDBTransactionHandler
- type PostDeletable
- type PostSaveable
- type PreDeletable
- type PreSaveable
- type Saveable
- type SetLogger
- type TransactionFunc
- type TransactionHandler
- type Transactioner
- type XODB
Constants ¶
const (
// ClubTableName is the name of the table for the Club model.
ClubTableName = "club"
)
const (
// CourseDetailsTableName is the name of the table for the CourseDetails model.
CourseDetailsTableName = "course_details"
)
const (
// CourseTableName is the name of the table for the Course model.
CourseTableName = "course"
)
const (
// HoleTableName is the name of the table for the Hole model.
HoleTableName = "hole"
)
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 ( // ErrNoPK is returned when a primary key is not set. ErrNoPK = errors.New("primary key is not set") )
var XOLog = func(msg string, args ...any) { DBLog(msg, args...) }
XOLog is a compat shim for DBLog
Functions ¶
func InsertManyClubs ¶
func InsertManyCourseDetailss ¶
func InsertManyCourseDetailss(db DB, ms ...*CourseDetails) error
func InsertManyCourses ¶
func InsertManyHoles ¶
Types ¶
type Club ¶
type Club struct {
Id int `db:"id,pk,autoinc"`
Name string `db:"name"`
Address1 string `db:"address1"`
Address2 string `db:"address2"`
Address3 string `db:"address3"`
Address4 string `db:"address4"`
PostalCode string `db:"postal_code"`
}
Club represents a row from 'club'.
func GetAllClubs ¶
GetAllClubs retrieves all rows from 'club' as a slice of Club.
Generated from table 'club'.
func (*Club) InsertClubWithPK ¶
func (*Club) InsertWithUpdate ¶
InsertWithUpdate inserts the Club to the database, and tries to update on unique constraint violations.
func (*Club) IsPrimaryKeySet ¶
IsPrimaryKeySet returns true if all primary key fields are set to none zero values
func (*Club) SaveOrUpdate ¶
SaveOrUpdate saves the Club to the database, but tries to update on unique constraint violations.
type Course ¶
type Course struct {
Id int `db:"id,pk,autoinc"`
ClubId int `db:"club_id"`
Name string `db:"name"`
}
Course represents a row from 'course'.
func GetAllCourses ¶
GetAllCourses retrieves all rows from 'course' as a slice of Course.
Generated from table 'course'.
func (*Course) GetClubIdClub ¶
GetClubIdClub Gets an instance of Club
Generated from constraint course_club_id_fk
func (*Course) InsertCourseWithPK ¶
func (*Course) InsertWithUpdate ¶
InsertWithUpdate inserts the Course to the database, and tries to update on unique constraint violations.
func (*Course) IsPrimaryKeySet ¶
IsPrimaryKeySet returns true if all primary key fields are set to none zero values
func (*Course) SaveOrUpdate ¶
SaveOrUpdate saves the Course to the database, but tries to update on unique constraint violations.
type CourseDetails ¶
type CourseDetails struct {
Id int `db:"id,pk,autoinc"`
CourseId int `db:"course_id"`
Marker string `db:"marker"`
SlopeRating int `db:"slope_rating"`
CourseRating float64 `db:"course_rating"`
ParFrontNine int `db:"par_front_nine"`
ParBackNine int `db:"par_back_nine"`
ParTotal int `db:"par_total"`
YardsFrontNine int `db:"yards_front_nine"`
YardsBackNine int `db:"yards_back_nine"`
YardsTotal int `db:"yards_total"`
MetersFrontNine int `db:"meters_front_nine"`
MetersBackNine int `db:"meters_back_nine"`
MetersTotal int `db:"meters_total"`
}
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 GetAllCourseDetailss ¶
func GetAllCourseDetailss(db DB, filters ...any) ([]*CourseDetails, error)
GetAllCourseDetailss retrieves all rows from 'course_details' as a slice of CourseDetails.
Generated from table 'course_details'.
func (*CourseDetails) Delete ¶
func (m *CourseDetails) Delete(db DB) error
Delete deletes the CourseDetails from the database.
func (*CourseDetails) GetCourseIdCourse ¶
func (m *CourseDetails) GetCourseIdCourse(db DB) (*Course, error)
GetCourseIdCourse 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) InsertCourseDetailsWithPK ¶
func (m *CourseDetails) InsertCourseDetailsWithPK(db DB) error
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) Patch ¶
func (m *CourseDetails) Patch(db DB, newT *CourseDetails) error
Patch updates the CourseDetails in the database.
Generated from primary key.
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
Get(dest any, query string, args ...any) error
Select(dest any, query string, args ...any) 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 Hole ¶
type Hole struct {
Id int `db:"id,pk,autoinc"`
DetailsId int `db:"details_id"`
Number int `db:"number"`
Par int `db:"par"`
StrokeIndex int `db:"stroke_index"`
DistanceYards int `db:"distance_yards"`
DistanceMeters int `db:"distance_meters"`
}
Hole represents a row from 'hole'.
func GetAllHoles ¶
GetAllHoles retrieves all rows from 'hole' as a slice of Hole.
Generated from table 'hole'.
func (*Hole) GetDetailsIdCourseDetails ¶
func (m *Hole) GetDetailsIdCourseDetails(db DB) (*CourseDetails, error)
GetDetailsIdCourseDetails Gets an instance of CourseDetails
Generated from constraint hole_details_id_fk
func (*Hole) InsertHoleWithPK ¶
func (*Hole) InsertWithUpdate ¶
InsertWithUpdate inserts the Hole to the database, and tries to update on unique constraint violations.
func (*Hole) IsPrimaryKeySet ¶
IsPrimaryKeySet returns true if all primary key fields are set to none zero values
func (*Hole) SaveOrUpdate ¶
SaveOrUpdate saves the Hole to the database, but tries to update on unique constraint violations.
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 Saveable ¶
Saveable is the interface implemented by types which can save themselves to the database.
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.