models

package
v0.0.1-0...-6ead36c Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2025 License: Apache-2.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.

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

View Source
const (
	// ClubTableName is the name of the table for the Club model.
	ClubTableName = "club"
)
View Source
const (
	// CourseDetailsTableName is the name of the table for the CourseDetails model.
	CourseDetailsTableName = "course_details"
)
View Source
const (
	// CourseTableName is the name of the table for the Course model.
	CourseTableName = "course"
)
View Source
const (
	// HoleTableName is the name of the table for the Hole model.
	HoleTableName = "hole"
)

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 (
	// ErrNoPK is returned when a primary key is not set.
	ErrNoPK = errors.New("primary key is not set")
)
View Source
var XOLog = func(msg string, args ...any) {
	DBLog(msg, args...)
}

XOLog is a compat shim for DBLog

Functions

func InsertManyClubs

func InsertManyClubs(db DB, ms ...*Club) error

func InsertManyCourseDetailss

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

func InsertManyCourses

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

func InsertManyHoles

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

func IsKeySet

func IsKeySet(x any) 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 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 ClubById

func ClubById(db DB, id int) (*Club, error)

ClubById retrieves a row from 'club' as a Club.

Generated from primary key.

func GetAllClubs

func GetAllClubs(db DB, filters ...any) ([]*Club, error)

GetAllClubs retrieves all rows from 'club' as a slice of Club.

Generated from table 'club'.

func (*Club) Delete

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

Delete deletes the Club from the database.

func (*Club) Insert

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

Insert inserts the Club to the database.

func (*Club) InsertClubWithPK

func (m *Club) InsertClubWithPK(db DB) error

func (*Club) InsertWithUpdate

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

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

func (*Club) IsPrimaryKeySet

func (m *Club) IsPrimaryKeySet() bool

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

func (*Club) Patch

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

Patch updates the Club in the database.

Generated from primary key.

func (*Club) Save

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

Save saves the Club to the database.

func (*Club) SaveOrUpdate

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

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

func (*Club) Update

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

Update updates the Club in the database.

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 CourseById

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

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

Generated from primary key.

func GetAllCourses

func GetAllCourses(db DB, filters ...any) ([]*Course, error)

GetAllCourses retrieves all rows from 'course' as a slice of Course.

Generated from table 'course'.

func (*Course) Delete

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

Delete deletes the Course from the database.

func (*Course) GetClubIdClub

func (m *Course) GetClubIdClub(db DB) (*Club, error)

GetClubIdClub Gets an instance of Club

Generated from constraint course_club_id_fk

func (*Course) Insert

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

Insert inserts the Course to the database.

func (*Course) InsertCourseWithPK

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

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) Patch

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

Patch updates the Course in the database.

Generated from primary key.

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,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

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,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

func GetAllHoles(db DB, filters ...any) ([]*Hole, error)

GetAllHoles retrieves all rows from 'hole' as a slice of Hole.

Generated from table '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) GetDetailsIdCourseDetails

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

GetDetailsIdCourseDetails Gets an instance of CourseDetails

Generated from constraint hole_details_id_fk

func (*Hole) Insert

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

Insert inserts the Hole to the database.

func (*Hole) InsertHoleWithPK

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

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) Patch

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

Patch updates the Hole in the database.

Generated from primary key.

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