db

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2022 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const DEFAULT_DB_DRIVER = "mysql"
View Source
const TEST_DB_DRIVER = "sqlite3"

Variables

View Source
var (
	ErrRedisErr = errors.New("Redis Script Error")
)

Functions

func CloseDB

func CloseDB()

CloseDB 关闭数据库连接

func Execute

func Execute(action Action) (obj interface{}, err error)

Execute 多表操作,使用事务处理

func GetDB

func GetDB() *gorm.DB

GetDB 获取数据库连接对象

func GetRedisScript

func GetRedisScript(cmd int) string

func InitDB

func InitDB(driver, dbConnStr string)

InitDB 初始化数据库连接

func InitDBForPoll

func InitDBForPoll(driver, dbConnStr string, maxConn int, idleConn int)

带连接池设置的DB对象

func MapScan

func MapScan(r *sql.Rows, dest map[string]interface{}) error

MapScan 从sql.Rows映射到map

func NewRedisScript

func NewRedisScript(commit, str string) int

func Query

func Query(queryStr string, values ...interface{}) ([]map[string]interface{}, error)

Query 通用查询方法,返回[]map queryStr 查询语句 values 参数 返回值:数据集合,错误 models.Query("SELECT * FROM tablename where id = ?",2)

func QueryCount

func QueryCount(queryStr string, values ...interface{}) (int64, error)

返回查询行数

func QueryForPage

func QueryForPage(pageIndex, pageSize int64, queryStr string, values ...interface{}) ([]map[string]interface{}, int64, error)

QueryForPage 通用分页查询方法 pageIndex 页码 pageSize 记录数 queryStr 查询语句 values 参数 返回值:数据集合,总记录数,错误 models.QueryForPage(1,10,"SELECT * FROM tablename where id = ?",2)

func RedisError

func RedisError(err error) bool

Types

type Action

type Action func(db *gorm.DB) (interface{}, error)

type Redis

type Redis struct {
	*redis.Client
	// contains filtered or unexported fields
}

func (*Redis) Script

func (r *Redis) Script(cmd int, keys []string, args ...interface{}) (interface{}, error)

func (*Redis) ScriptInt64

func (r *Redis) ScriptInt64(cmd int, keys []string, args ...interface{}) (int64, error)

func (*Redis) ScriptStr

func (r *Redis) ScriptStr(cmd int, keys []string, args ...interface{}) (string, error)

type RedisConfig

type RedisConfig struct {
	Addr     string
	Passwd   string
	PoolSize int
}

type RedisManager

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

func NewRedisManager

func NewRedisManager(conf *RedisConfig) *RedisManager

func (*RedisManager) Add

func (r *RedisManager) Add(id int, conf *RedisConfig)

func (*RedisManager) Exist

func (r *RedisManager) Exist(id int) bool

func (*RedisManager) GetByRid

func (r *RedisManager) GetByRid(rid int) *Redis

func (*RedisManager) GetGlobal

func (r *RedisManager) GetGlobal() *Redis

func (*RedisManager) Sub

func (r *RedisManager) Sub(fun func(channel, data string), channels ...string)

Jump to

Keyboard shortcuts

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