gormi

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2024 License: MIT Imports: 12 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultV2 = New2(logi.Default.Logger, &logger.Config{
		SlowThreshold: 100 * time.Millisecond,
		LogLevel:      logger.Warn,
		Colorful:      true,
	})
)

Functions

func GetById

func GetById[T any](db *gorm.DB, id int) (*T, error)

func GetDB

func GetDB(db *gorm.DB, log *log.Logger, conf *logger.Config) *gorm.DB

func New2

func New2(loger *zap.Logger, conf *logger.Config) logger.Interface

Types

type ChainDao

type ChainDao struct {
	Ctx          context.Context
	DB, OriginDB *gorm.DB
}

func NewChainDao

func NewChainDao(ctx context.Context, db *gorm.DB) *ChainDao

func (*ChainDao) ById

func (c *ChainDao) ById(id int) *ChainDao

func (*ChainDao) ByName

func (c *ChainDao) ByName(name string) *ChainDao

func (*ChainDao) ResetDB

func (c *ChainDao) ResetDB()

type Config

type Config struct {
	SlowThreshold time.Duration
	Colorful      bool
	LogLevel      zapcore.Level
}

type DB

type DB[T any] gorm.DB

func (*DB[T]) GetById

func (db *DB[T]) GetById(id int) (*T, error)

type DB2

type DB2[T any] struct {
	gorm.DB
}

func (*DB2[T]) GetById

func (db *DB2[T]) GetById(id int) (*T, error)

type FilterExpressions

type FilterExpressions []dbi.FilterExpression

func (FilterExpressions) BuildORM

func (f FilterExpressions) BuildORM(odb *gorm.DB) *gorm.DB

type GORMConfig

type GORMConfig struct {
	Config gorm.Config
	Logger logger.Config
}

func (*GORMConfig) Init

func (c *GORMConfig) Init()

type ModelTime

type ModelTime struct {
	CreatedAt time.Time `json:"created_at" gorm:"default:current_timestamp"`
	UpdatedAt time.Time `json:"updated_at"`
	DeletedAt time.Time `json:"deleted_at" gorm:"default:null"`
}

type Repository

type Repository[T any] struct {
	ChainDao
}

func NewRepository

func NewRepository[T any](ctx context.Context, db *gorm.DB) *Repository[T]

func (*Repository[T]) Create

func (r *Repository[T]) Create(t *T) error

func (*Repository[T]) Delete

func (r *Repository[T]) Delete(id int) error

func (*Repository[T]) Read

func (r *Repository[T]) Read(id int) (*T, error)

func (*Repository[T]) Update

func (r *Repository[T]) Update(t *T) error

type SQLLogger

type SQLLogger struct {
	*zap.Logger
	*logger.Config
}

func (*SQLLogger) Error

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

Error print error messages

func (*SQLLogger) Info

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

Info print info

func (*SQLLogger) LogMode

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

LogMode log mode

func (*SQLLogger) Trace

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

Trace print sql message 只有这里的context不是background,看了代码,也没用

func (*SQLLogger) Warn

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

Warn print warn messages

Directories

Path Synopsis
mysql

Jump to

Keyboard shortcuts

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