Documentation ¶
Index ¶
- Variables
- func IsKeySet(x interface{}) bool
- type DB
- type DBTransactionHandler
- type DBTransactioner
- type Deletable
- type LoggableDBTransactionHandler
- type PostDeletable
- type PostSaveable
- type PreDeletable
- type PreSaveable
- type Saveable
- type SetLogger
- type TransactionFunc
- type TransactionHandler
- type Transactioner
- type XODB
Constants ¶
This section is empty.
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 XOLog = func(msg string, args ...any) { DBLog(msg, args...) }
XOLog is a compat shim for DBLog
Functions ¶
Types ¶
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 ¶
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 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.