mysql

package
v0.0.0-...-da57006 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2019 License: Apache-2.0 Imports: 17 Imported by: 0

README

MySql-Go

Build Status Go Report Card GoDoc
Golang Mysql操作。

基于Mysql Sqlx进行构建

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCacheIsNil = errors.New("*DB.Cache (redis) is nil")

ErrCacheIsNil db cache(redis) is nil

View Source
var ErrNoRows = sql.ErrNoRows

ErrNoRows no rows

Functions

func IsNoRows

func IsNoRows(err error) bool

IsNoRows

Types

type CacheDB

type CacheDB struct {
	*DB
	// contains filtered or unexported fields
}

CacheDB

func (*CacheDB) CreateCacheKey

func (c *CacheDB) CreateCacheKey(structPtr Cacheable, fields ...string) (CacheKey, reflect.Value, error)

CreateCacheKey create table cache key and fields values

func (*CacheDB) CreateCacheKeyByFields

func (c *CacheDB) CreateCacheKeyByFields(fields []string, values []interface{}) (string, error)

CreateCacheKeyByFields create cache key by fields

func (*CacheDB) CreateGetQuery

func (c *CacheDB) CreateGetQuery(whereFields ...string) string

CreateGetQuery get model by where fields ...

func (*CacheDB) DeleteCache

func (c *CacheDB) DeleteCache(structPtr Cacheable, fields ...string) error

DeleteCache

func (*CacheDB) GetCache

func (c *CacheDB) GetCache(structPtr Cacheable, fields ...string) error

GetCache

func (*CacheDB) GetCacheByWhere

func (c *CacheDB) GetCacheByWhere(structPtr Cacheable, whereNamedCond string) error

GetCacheByWhere

func (*CacheDB) PutCache

func (c *CacheDB) PutCache(structPtr Cacheable, fields ...string) error

PutCache

type CacheKey

type CacheKey struct {
	Key         string
	FieldValues []interface{}
	// contains filtered or unexported fields
}

CacheKey table cache fields

type Cacheable

type Cacheable interface {
	TableName() string
}

Cacheable

type Column

type Column struct {
	ColumnName string `json:"COLUMN_NAME" db:"COLUMN_NAME"`
	ColumnKey  string `json:"COLUMN_KEY" db:"COLUMN_KEY"`
}

Column db column

type Config

type Config struct {
	Database     string
	Username     string
	Password     string
	Host         string
	Port         int
	MaxIdleConns int `yaml:"max_idle_conns"`
	MaxOpenConns int `yaml:"max_open_conns"`
	// ConnMaxLifetime time: second
	ConnMaxLifetime int64 `yaml:"conn_max_lifetime"`
	// db redis cache
	CloseCache bool `yaml:"close_cache"`
}

Config ooz mysql db config

func NewConfig

func NewConfig() *Config

NewConfig creates db default config.

func (*Config) Source

func (cfg *Config) Source() string

Source mysql connection source.

type DB

type DB struct {
	*sqlx.DB
	Cache *redis.Client
	// contains filtered or unexported fields
}

DB mysql db and cache redi.

func Connect

func Connect(dbConfig *Config, redisConfig *redis.Config) (*DB, error)

Connect connection db.

func (*DB) Callback

func (d *DB) Callback(fn func(sqlx.DbAndTx) error, tx ...*sqlx.Tx) error

Callback

func (*DB) CallbackInSession

func (d *DB) CallbackInSession(fn func(context.Context, *sqlx.Conn) error, ctx ...context.Context) error

CallbackInSession

func (*DB) GetCacheDB

func (d *DB) GetCacheDB(tableName string) (*CacheDB, error)

GetCacheDB

func (*DB) RegisterCacheDB

func (d *DB) RegisterCacheDB(ormStruct Cacheable, expire time.Duration) (*CacheDB, error)

RegisterCacheDB register a cache table.

func (*DB) TransactCallback

func (d *DB) TransactCallback(fn func(*sqlx.Tx) error, tx ...*sqlx.Tx) (err error)

TransactCallback

func (*DB) TransactCallbackInSession

func (d *DB) TransactCallbackInSession(fn func(context.Context, *sqlx.Tx) error, ctx ...context.Context) (err error)

TransactCallbackInSession

type Int32s

type Int32s []int32

Int32s db column value type.

func (*Int32s) Scan

func (i *Int32s) Scan(value interface{}) error

Scan implements the sql.Scanner interface.

func (Int32s) Value

func (i Int32s) Value() (driver.Value, error)

Value implements the driver.Valuer interface.

type Int8IFaceMap

type Int8IFaceMap map[int8]interface{}

Int8IFaceMap db column value type.

func (*Int8IFaceMap) Scan

func (i *Int8IFaceMap) Scan(value interface{}) error

Scan implements the sql.Scanner interface.

func (Int8IFaceMap) Value

func (i Int8IFaceMap) Value() (driver.Value, error)

Value implements the driver.Valuer interface.

type IntStringMap

type IntStringMap map[int]string

IntStringMap db column value type.

func (*IntStringMap) Scan

func (i *IntStringMap) Scan(value interface{}) error

Scan implements the sql.Scanner interface.

func (IntStringMap) Value

func (i IntStringMap) Value() (driver.Value, error)

Value implements the driver.Valuer interface.

type PreDB

type PreDB struct {
	*DB
	// contains filtered or unexported fields
}

PreDB

func NewPreDB

func NewPreDB() *PreDB

NewPreDB

func (*PreDB) InitByRdsCfg

func (p *PreDB) InitByRdsCfg(dbConfig *Config, redisConfig *redis.Config) (err error)

InitByRdsCfg

func (*PreDB) InitByRdsClient

func (p *PreDB) InitByRdsClient(dbConfig *Config, redisCient *redis.Client) (err error)

InitByRdsClient

func (*PreDB) RegisterCacheDB

func (p *PreDB) RegisterCacheDB(ormStructPtr Cacheable, cacheExpiration time.Duration, initQuery string, args ...interface{}) (*CacheDB, error)

RegisterCacheDB

type Strings

type Strings []string

Strings db column value type.

func (*Strings) Scan

func (s *Strings) Scan(value interface{}) error

Scan implements the sql.Scanner interface.

func (Strings) Value

func (s Strings) Value() (driver.Value, error)

Value implements the driver.Valuer interface.

Jump to

Keyboard shortcuts

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