orm

package
v1.0.15 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoRow          = sql.ErrNoRows
	ErrRecordNotFound = gorm.ErrRecordNotFound

	LogLevelMap = map[string]logger.LogLevel{
		"info":   logger.Info,
		"warn":   logger.Warn,
		"error":  logger.Error,
		"silent": logger.Silent,
	}
)

Functions

func InitGorm

func InitGorm(c *MySQLConfig) (db *gorm.DB)

Types

type MySQLConfig

type MySQLConfig struct {
	DSN            string         `json:"dsn" toml:"dsn" yaml:"dsn"`                                        // data source name.
	MaxOpenConn    int            `json:"max_open_conn" toml:"max_open_conn" yaml:"max_open_conn"`          // pool, e.g:10
	MaxIdleConn    int            `json:"max_idle_conn" toml:"max_idle_conn" yaml:"max_idle_conn"`          // pool, e.g:100
	MaxConnTimeout xtime.Duration `json:"max_conn_timeout" toml:"max_conn_timeout" yaml:"max_conn_timeout"` // connect max life time. Unmarshal config file e.g: 10s、2m、1m10s
	LogLevel       string         `json:"log_level" toml:"log_level" yaml:"log_level"`                      // enum: info、warn、error、silent, default warn
	Colorful       bool           `json:"colorful" toml:"colorful" yaml:"colorful"`                         // is colorful log, default false
	SlowThreshold  xtime.Duration `json:"slow_threshold" toml:"slow_threshold" yaml:"slow_threshold"`       // slow sql log. Unmarshal config file e.g: 100ms、200ms、300ms、1s, default 200ms
}

MySQLConfig mysql config.

type Page

type Page struct {
	PageNo   int `json:"page_no"`
	PageSize int `json:"page_size"`
}

func (*Page) Apply added in v1.0.11

func (p *Page) Apply(db *gorm.DB)

type Redis

type Redis struct {
	Redis *redis.Client
}

func InitRedis

func InitRedis(c *RedisConfig) (r *Redis)

func (*Redis) Transaction

func (r *Redis) Transaction(ctx context.Context, fc func(tx redis.Pipeliner) error) error

type RedisCluster

type RedisCluster struct {
	Redis *redis.ClusterClient
}

func InitRedisCluster

func InitRedisCluster(c *RedisConfig) (rc *RedisCluster)

func (*RedisCluster) Transaction

func (r *RedisCluster) Transaction(ctx context.Context, fc func(tx redis.Pipeliner) error) error

type RedisConfig

type RedisConfig struct {
	Addrs        []string       `json:"addrs" yaml:"addrs" toml:"addrs"`
	Password     string         `json:"password" yaml:"password" toml:"password"`
	DB           int            `json:"db" yaml:"db" toml:"db"`
	ReadTimeout  xtime.Duration `json:"read_timeout" yaml:"read_timeout" toml:"read_timeout"`
	WriteTimeout xtime.Duration `json:"write_timeout" yaml:"write_timeout" toml:"write_timeout"`
}

RedisConfig redis config.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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