gormex

package
v0.0.0-...-70ec780 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BATCH_SIZE = 1000 // default batch size
)
View Source
const (
	DbTXPrefix string = "_db_transaction"
)
View Source
const (
	SqlLogFormat = "elapsed:%dms,affect:%d,err:%s,sql:%s"
)

Variables

View Source
var MySqlComponent = embedded.NewComponent[*gorm.DB]()

Functions

func BaseGroup

func BaseGroup[T dependency.IEntity](f func(v ...T) (int64, error), opt dependency.BaseOption, p ...T) (int64, error)

func CoreFrmCtx

func CoreFrmCtx(ctx context.Context, id string) *gorm.DB

func GetTransactionDb

func GetTransactionDb(id string) *gorm.DB

func Log

func Log(ctx context.Context, lvl iLog.Level, msg string)

func NewContext

func NewContext(ctx context.Context, id string, newdb *gorm.DB) context.Context

func NewLogger

func NewLogger() logger.Interface

func NewMySqlClient

func NewMySqlClient(dsn string, log logger.Interface) (*gorm.DB, error)

reference docs: https://github.com/go-sql-driver/mysql#dsn-data-source-name dsn := "user:pass@tcp(127.0.0.1:3306)/dbname?charset=utf8mb4&parseTime=True&loc=Local&timeout=1m" NewMySqlClient new a mysql client by dsn with logger

func NewUnitOfWork

func NewUnitOfWork(id string) dependency.IUnitOfWork

func ReadOnly

func ReadOnly(ctx context.Context, id string) *gorm.DB

func SetDisableQueryFields

func SetDisableQueryFields()

func SyncDbSruct

func SyncDbSruct(pos ...dependency.IPo) error

func WithContext

func WithContext(ctx context.Context, id string) *gorm.DB

Types

type BaseRepository

type BaseRepository[T dependency.IEntity] struct{} // base repository

func (*BaseRepository[T]) BaseCount

func (r *BaseRepository[T]) BaseCount(ctx context.Context, opt dependency.BaseOption, p T) (int64, error)

BaseCount

func (*BaseRepository[T]) BaseCreate

func (r *BaseRepository[T]) BaseCreate(ctx context.Context, opt dependency.BaseOption, p ...T) (int64, error)

BaseCreate

func (*BaseRepository[T]) BaseDelete

func (r *BaseRepository[T]) BaseDelete(ctx context.Context, opt dependency.BaseOption, p T) (int64, error)

BaseDelete

func (*BaseRepository[T]) BaseGet

func (r *BaseRepository[T]) BaseGet(ctx context.Context, opt dependency.BaseOption, p T) (int64, error)

BaseGet

func (*BaseRepository[T]) BaseQuery

func (r *BaseRepository[T]) BaseQuery(ctx context.Context, opt dependency.BaseOption, p T) ([]T, error)

BaseQuery

func (*BaseRepository[T]) BaseSave

func (r *BaseRepository[T]) BaseSave(ctx context.Context, opt dependency.BaseOption, p ...T) (int64, error)

BaseSave

func (*BaseRepository[T]) BaseUpdate

func (r *BaseRepository[T]) BaseUpdate(ctx context.Context, opt dependency.BaseOption, p T) (int64, error)

BaseUpdate

func (*BaseRepository[T]) BuildConds

func (r *BaseRepository[T]) BuildConds(ctx context.Context, p T, readOnly bool, conds ...any) *gorm.DB

func (*BaseRepository[T]) BuildFrmOption

func (r *BaseRepository[T]) BuildFrmOption(ctx context.Context, p T, opt dependency.BaseOption) *gorm.DB

type ContextKey

type ContextKey string

func GetDbTX

func GetDbTX(id string) ContextKey

type GormLogger

type GormLogger struct {
	LogLevel                  logger.LogLevel
	IgnoreRecordNotFoundError bool
	SlowThreshold             time.Duration
	// contains filtered or unexported fields
}

func (*GormLogger) Error

func (l *GormLogger) Error(ctx context.Context, msg string, args ...interface{})

func (*GormLogger) Info

func (l *GormLogger) Info(ctx context.Context, msg string, args ...interface{})

func (*GormLogger) LogMode

func (l *GormLogger) LogMode(level logger.LogLevel) logger.Interface

func (*GormLogger) Trace

func (l *GormLogger) Trace(ctx context.Context, begin time.Time, fc func() (sql string, rowsAffected int64), err error)

func (*GormLogger) Warn

func (l *GormLogger) Warn(ctx context.Context, msg string, args ...interface{})

type GormTransactionImpl

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

func (*GormTransactionImpl) Execute

func (t *GormTransactionImpl) Execute(ctx context.Context, fs ...dependency.DbAction) (e error)

Execute An execution function is passed in, and transactions are executed within the function.

Jump to

Keyboard shortcuts

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