models

package
v0.0.27 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2025 License: Apache-2.0 Imports: 13 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.

Index

Constants

View Source
const (
	// GoschemaMigrationHistoryTableName is the name of the table for the GoschemaMigrationHistory model.
	GoschemaMigrationHistoryTableName = "goschema_migration_history"
)
View Source
const (
	// GoschemaMigrationVersionTableName is the name of the table for the GoschemaMigrationVersion model.
	GoschemaMigrationVersionTableName = "goschema_migration_version"
)

Variables

View Source
var (
	GoschemaMigrationHistoryActionMigratingUp    = usql.NewEnum("migrating_up")
	GoschemaMigrationHistoryActionMigratingDown  = usql.NewEnum("migrating_down")
	GoschemaMigrationHistoryActionMigratedUp     = usql.NewEnum("migrated_up")
	GoschemaMigrationHistoryActionMigratedDown   = usql.NewEnum("migrated_down")
	GoschemaMigrationHistoryActionMigrationError = usql.NewEnum("migration_error")
)

Valid values for the 'Action' enum column

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 InsertManyGoschemaMigrationHistorys added in v0.0.15

func InsertManyGoschemaMigrationHistorys(db DB, ms ...*GoschemaMigrationHistory) error

func InsertManyGoschemaMigrationVersions added in v0.0.15

func InsertManyGoschemaMigrationVersions(db DB, ms ...*GoschemaMigrationVersion) error

func IsKeySet added in v0.0.15

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 DB added in v0.0.15

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 added in v0.0.15

type DBTransactionHandler struct {
	// contains filtered or unexported fields
}

DBTransactionHandler handles a transaction that will return any error.

func NewDBTransactionHandler added in v0.0.15

func NewDBTransactionHandler(db Transactioner) *DBTransactionHandler

NewDBTransactionHandler returns a configured instance of DBTransactionHandler

func (*DBTransactionHandler) Handle added in v0.0.15

Handle implements the TransactionHandler interface.

type DBTransactioner added in v0.0.15

type DBTransactioner interface {
	DB
	Transactioner
}

DBTransactioner is the interface that database connections that can utilise transactions should implement.

type Deletable added in v0.0.15

type Deletable interface {
	Delete(db DB) error
}

Deletable is the interface implemented by types which can delete themselves from the database.

type GoschemaMigrationHistory added in v0.0.15

type GoschemaMigrationHistory struct {
	Id        int       `db:"id,pk,autoinc"`
	Version   string    `db:"version"`
	Action    usql.Enum `db:"action"`
	CreatedAt time.Time `db:"created_at"`
}

GoschemaMigrationHistory represents a row from 'goschema_migration_history'.

func GetAllGoschemaMigrationHistorys added in v0.0.25

func GetAllGoschemaMigrationHistorys(db DB, filters ...any) ([]*GoschemaMigrationHistory, error)

GetAllGoschemaMigrationHistorys retrieves all rows from 'goschema_migration_history' as a slice of GoschemaMigrationHistory.

Generated from table 'goschema_migration_history'.

func GoschemaMigrationHistoryById added in v0.0.15

func GoschemaMigrationHistoryById(db DB, id int) (*GoschemaMigrationHistory, error)

GoschemaMigrationHistoryById retrieves a row from 'goschema_migration_history' as a GoschemaMigrationHistory.

Generated from primary key.

func (*GoschemaMigrationHistory) Delete added in v0.0.15

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

Delete deletes the GoschemaMigrationHistory from the database.

func (*GoschemaMigrationHistory) Insert added in v0.0.15

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

Insert inserts the GoschemaMigrationHistory to the database.

func (*GoschemaMigrationHistory) InsertWithUpdate added in v0.0.15

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

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

func (*GoschemaMigrationHistory) IsPrimaryKeySet added in v0.0.15

func (m *GoschemaMigrationHistory) IsPrimaryKeySet() bool

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

func (*GoschemaMigrationHistory) Patch added in v0.0.15

Patch updates the GoschemaMigrationHistory in the database.

Generated from primary key.

func (*GoschemaMigrationHistory) Save added in v0.0.15

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

Save saves the GoschemaMigrationHistory to the database.

func (*GoschemaMigrationHistory) SaveOrUpdate added in v0.0.15

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

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

func (*GoschemaMigrationHistory) Update added in v0.0.15

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

Update updates the GoschemaMigrationHistory in the database.

type GoschemaMigrationVersion added in v0.0.15

type GoschemaMigrationVersion struct {
	Version   string    `db:"version,pk"`
	IsCurrent bool      `db:"is_current"`
	CreatedAt time.Time `db:"created_at"`
}

GoschemaMigrationVersion represents a row from 'goschema_migration_version'.

func GetAllGoschemaMigrationVersions added in v0.0.25

func GetAllGoschemaMigrationVersions(db DB, filters ...any) ([]*GoschemaMigrationVersion, error)

GetAllGoschemaMigrationVersions retrieves all rows from 'goschema_migration_version' as a slice of GoschemaMigrationVersion.

Generated from table 'goschema_migration_version'.

func GoschemaMigrationVersionByVersion added in v0.0.15

func GoschemaMigrationVersionByVersion(db DB, version string) (*GoschemaMigrationVersion, error)

GoschemaMigrationVersionByVersion retrieves a row from 'goschema_migration_version' as a GoschemaMigrationVersion.

Generated from primary key.

func (*GoschemaMigrationVersion) Delete added in v0.0.15

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

Delete deletes the GoschemaMigrationVersion from the database.

func (*GoschemaMigrationVersion) Insert added in v0.0.15

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

Insert inserts the GoschemaMigrationVersion to the database.

func (*GoschemaMigrationVersion) InsertWithUpdate added in v0.0.15

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

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

func (*GoschemaMigrationVersion) IsPrimaryKeySet added in v0.0.15

func (m *GoschemaMigrationVersion) IsPrimaryKeySet() bool

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

func (*GoschemaMigrationVersion) Patch added in v0.0.15

Patch updates the GoschemaMigrationVersion in the database.

Generated from primary key.

func (*GoschemaMigrationVersion) Save added in v0.0.15

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

Save saves the GoschemaMigrationVersion to the database.

func (*GoschemaMigrationVersion) SaveOrUpdate added in v0.0.15

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

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

func (*GoschemaMigrationVersion) Update added in v0.0.15

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

Update updates the GoschemaMigrationVersion in the database.

type LoggableDBTransactionHandler added in v0.0.15

type LoggableDBTransactionHandler struct {
	// contains filtered or unexported fields
}

LoggableDBTransactionHandler handles a transaction and logs any error.

func NewLoggableDBTransactionHandler added in v0.0.15

func NewLoggableDBTransactionHandler(db Transactioner, l *slog.Logger) *LoggableDBTransactionHandler

NewLoggableDBTransactionHandler returns a configured instance of LoggableDBTransactionHandler

type PostDeletable added in v0.0.15

type PostDeletable interface {
	PostDelete() error
}

PostDeletable is the interface implemented by types which run a post delete step.

type PostSaveable added in v0.0.15

type PostSaveable interface {
	PostSave() error
}

PostSaveable is the interface implemented by types which run a post save step.

type PreDeletable added in v0.0.15

type PreDeletable interface {
	PreDelete() error
}

PreDeletable is the interface implemented by types which run a pre delete step.

type PreSaveable added in v0.0.15

type PreSaveable interface {
	PreSave(db DB) error
}

PreSaveable is the interface implemented by types which run a pre save step.

type Saveable added in v0.0.15

type Saveable interface {
	Save(db DB) error
}

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

type SetLogger added in v0.0.15

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 added in v0.0.15

type TransactionFunc func(db DB) error

TransactionFunc is a function to be called within a transaction.

type TransactionHandler added in v0.0.15

type TransactionHandler interface {
	Handle(TransactionFunc) error
}

type Transactioner added in v0.0.15

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

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

type XODB added in v0.0.15

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
⌂ 换网址