database

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: May 24, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrCodeCommitFailed   = "DB_COMMIT_FAILED"
	ErrCodeRollbackFailed = "DB_ROLLBACK_FAILED"
)

Variables

View Source
var (
	DBCtxKey   = context.CtxKey("_fw_db")
	DBTxCtxKey = context.CtxKey("_fw_db_tx")
)

Functions

func CreateDBName

func CreateDBName(conf config.Config) string

func GetDBFromCtx

func GetDBFromCtx(ctx context.Context) *gorm.DB

func MustOpenGORM

func MustOpenGORM(conf config.Config, dbName string, lf *log.LoggerFactory) *gorm.DB

func NewGooseLogger

func NewGooseLogger(logger log.Logger) goose.Logger

func NewGormLogger

func NewGormLogger(logger log.Logger) gormlogger.Interface

func OnDBStop

func OnDBStop(db DB) error

Types

type DB

type DB struct {
	*gorm.DB
	DbName string
}

func NewDB

func NewDB(conf config.Config, lf *log.LoggerFactory) DB

NewDB creates a new database instance

func (DB) HealthCheck

func (d DB) HealthCheck() error

func (DB) SetCtx

func (d DB) SetCtx(ctx context.Context) context.Context

type DBTx

type DBTx struct {
	*gorm.DB
	// contains filtered or unexported fields
}

func GetDBTxFromCtx

func GetDBTxFromCtx(ctx context.Context) *DBTx

func InTx

func InTx(ctx context.Context) *DBTx

func WithTx

func WithTx(ctx context.Context, txOptions ...*sql.TxOptions) (*DBTx, context.Context)

func (*DBTx) Commit

func (t *DBTx) Commit() *gorm.DB

func (*DBTx) DeferredCommitOrRollback

func (t *DBTx) DeferredCommitOrRollback(err *error)

func (*DBTx) IsAutomatic

func (t *DBTx) IsAutomatic() bool

func (*DBTx) IsClosed

func (t *DBTx) IsClosed() bool

func (*DBTx) IsSub

func (t *DBTx) IsSub() bool

func (*DBTx) Rollback

func (t *DBTx) Rollback() *gorm.DB

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL