mysql

package
v1.20.1 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConditionTypeLte = "<="
	ConditionTypeLt  = "<"
	ConditionTypeGte = ">="
	ConditionTypeGt  = ">"
	ConditionTypeEq  = "="
	ConditionTypeIn  = "in"
)

Variables

View Source
var (
	MissingUpdates = errors.New("更新内容为空")
)

Functions

func FilterDeleted

func FilterDeleted() func(db *gorm.DB) *gorm.DB

func NewKidLogger

func NewKidLogger(config *gLogger.Config) gLogger.Interface

func Paginate

func Paginate(pageNum, pageSize int) func(db *gorm.DB) *gorm.DB
func Search(wheres []*WhereWrapper) func(db *gorm.DB) *gorm.DB

Search 搜索 多个值 当有值

func SearchScope

func SearchScope(wheres where.Wheres) func(db *gorm.DB) *gorm.DB

func Where

func Where(wheres []*WhereWrapper) func(db *gorm.DB) *gorm.DB

func Wheres

func Wheres(wheres where.Wheres) func(db *gorm.DB) *gorm.DB

Types

type AutoMigrate

type AutoMigrate interface {
	Models() []interface{}
}

type KidLogger

type KidLogger struct {
	logger.Logger
	*gLogger.Config
	// contains filtered or unexported fields
}

func (*KidLogger) Error

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

func (*KidLogger) Info

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

func (*KidLogger) LogMode

func (log *KidLogger) LogMode(level gLogger.LogLevel) gLogger.Interface

func (*KidLogger) Trace

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

func (*KidLogger) Warn

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

type MySQL

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

func New

func New(opts ...Option) *MySQL

func (*MySQL) Provide

func (conn *MySQL) Provide(ctx context.Context) interface{}

type Option

type Option func(*Options)

func WithDb

func WithDb(dbName string) Option

func WithHost

func WithHost(host string) Option

func WithLogLevel

func WithLogLevel(logLevel int) Option

func WithMaxIdle

func WithMaxIdle(maxIdle int) Option

func WithMaxLife

func WithMaxLife(maxLife time.Duration) Option

func WithMaxOpen

func WithMaxOpen(maxOpen int) Option

func WithPassword

func WithPassword(password string) Option

func WithPort

func WithPort(port int) Option

func WithUser

func WithUser(user string) Option

type Options

type Options struct {
	User     string        // 数据库用户名
	Password string        // 数据库密码
	Host     string        // 数据库连接地址
	Port     int           // 数据库连接端口
	Db       string        // 数据库库名
	MaxIdle  int           // 最大空闲连接数
	MaxOpen  int           // 最大连接数
	MaxLife  time.Duration // 连接最大存活时间
	LogLevel int           // 日志级别
}

type Repository

type Repository struct {
	DB *MySQL `inject:""`
}

func (*Repository) Create

func (repo *Repository) Create(creator *creator.Creator) error

func (*Repository) Delete

func (repo *Repository) Delete(deleter *deleter.Deleter) error

func (*Repository) Exec

func (repo *Repository) Exec(tx context.Context, sql string, args ...interface{}) error

func (*Repository) Exist

func (repo *Repository) Exist(finder *finder.Finder) bool

func (*Repository) Find

func (repo *Repository) Find(finder *finder.Finder) error

func (*Repository) GetDb

func (repo *Repository) GetDb(ctx context.Context) interface{}

func (*Repository) GetOne

func (repo *Repository) GetOne(finder *finder.Finder) error

func (*Repository) GetUniqueID

func (repo *Repository) GetUniqueID(finder *finder.Finder, min, max, ignoreStart, ignoreEnd int64) int64

func (*Repository) Provide

func (repo *Repository) Provide(context.Context) interface{}

func (*Repository) Raw

func (repo *Repository) Raw(tx context.Context, sql string, args ...interface{}) error

func (*Repository) Transaction

func (repo *Repository) Transaction(txFunc func(context.Context) error) error

func (*Repository) Update

func (repo *Repository) Update(updater *updater.Updater) error

type WhereWrapper

type WhereWrapper struct {
	Column    string
	Condition string
	Value     interface{}
}

func NewWhereWrapper

func NewWhereWrapper(col string, condition string, val interface{}) *WhereWrapper

func Wrappers

func Wrappers(conditions ...*WhereWrapper) []*WhereWrapper

Jump to

Keyboard shortcuts

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