gorm

package
v0.0.0-...-d853fe5 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2023 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DBKey dbKeyType

Functions

func CheckMysqlDatabase

func CheckMysqlDatabase(c Config) error

CheckMysqlDatabase 检查数据库是否存在,不存在则创建, for mysql

func ModelMap

func ModelMap(c entity.Context, i any) map[string]any

ModelMap 把model转换成map, 为了能够更新空字段

func ParseGormLevel

func ParseGormLevel(lvl string) logger.LogLevel

ParseLevel takes a string level and returns the Logrus log level constant.

func RawTableName

func RawTableName(i any) string

Types

type AInt32

type AInt32 []int32

func (*AInt32) Scan

func (c *AInt32) Scan(input any) error

func (AInt32) Value

func (c AInt32) Value() (driver.Value, error)

type AInt64

type AInt64 []int64

func (*AInt64) Scan

func (c *AInt64) Scan(input any) error

func (AInt64) Value

func (c AInt64) Value() (driver.Value, error)

type AString

type AString []string

func (*AString) Scan

func (c *AString) Scan(input any) error

func (AString) Value

func (c AString) Value() (driver.Value, error)

type Config

type Config struct {
	// for log
	SlowThreshold time.Duration `json:"slow_threshold" yaml:"slow_threshold"`

	LogLevel string `json:"log_level" yaml:"log_level"`
	UserName string `json:"user_name" yaml:"user_name"`
	Password string `json:"password" yaml:"password"`
	Protocol string `json:"protocol" yaml:"protocol"`
	Host     string `json:"host" yaml:"host"`
	DBName   string `json:"db_name" yaml:"db_name"`

	MaxOpen int `json:"max_open" yaml:"max_open"`
	MaxIdle int `json:"max_idle" yaml:"max_idle"`
	MaxLife int `json:"max_life" yaml:"max_life"`

	Charset string `json:"charset" yaml:"charset"`

	Params map[string]string `json:"params" yaml:"params"`

	//DatabaseType default mysql
	DatabaseType string `json:"database_type" yaml:"database_type"`

	Tabler
}

type GormDB

type GormDB struct {
	*Config
	// contains filtered or unexported fields
}

MysqlDB 数据库操作实例

func FormatGormDB

func FormatGormDB(db *gorm.DB) *GormDB

func NewGormDB

func NewGormDB(c Config) *GormDB

func NewOnlyReadGormDB

func NewOnlyReadGormDB(c Config) *GormDB

func (*GormDB) Begin

func (c *GormDB) Begin() *GormDB

func (*GormDB) C

func (c *GormDB) C(ctx entity.Context, forupdate ...int) *gorm.DB

func (*GormDB) DB

func (c *GormDB) DB() *gorm.DB

func (*GormDB) Model

func (c *GormDB) Model(ctx entity.Context, model any, forupdate ...int) *gorm.DB

func (*GormDB) Table

func (gdb *GormDB) Table(c entity.Context, i any) func(db *gorm.DB) *gorm.DB

type GormLog

type GormLog struct {
	*LogConfig
	// contains filtered or unexported fields
}

func NewGormLog

func NewGormLog(c LogConfig) *GormLog

func (*GormLog) Error

func (m *GormLog) Error(c entity.Context, s string, p ...any)

func (*GormLog) Info

func (m *GormLog) Info(c entity.Context, s string, p ...any)

func (*GormLog) LogMode

func (m *GormLog) LogMode(logger.LogLevel) logger.Interface

func (*GormLog) Trace

func (m *GormLog) Trace(c entity.Context,
	begin time.Time, fc func() (string, int64), err error)

func (*GormLog) Warn

func (m *GormLog) Warn(c entity.Context, s string, p ...any)

type LogConfig

type LogConfig struct {
	SlowThreshold time.Duration
	Colorful      bool
	LogLevel      logger.LogLevel
}

type Tabler

type Tabler interface {
	TableName(c entity.Context, i any) string
}

type Transaction

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

func NewTransaction

func NewTransaction(db *GormDB) *Transaction

func (*Transaction) Begin

func (t *Transaction) Begin(c entity.Context) entity.Context

func (*Transaction) Commit

func (t *Transaction) Commit(c entity.Context)

func (*Transaction) DB

func (t *Transaction) DB(c entity.Context) *GormDB

for get GormDB

func (*Transaction) Rollback

func (t *Transaction) Rollback(c entity.Context, e error)

Jump to

Keyboard shortcuts

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