dbrouter

package
v1.4.13 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2021 License: BSD-3-Clause Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DB_TYPE_MONGO    = "mongo"
	DB_TYPE_MYSQL    = "mysql"
	DB_TYPE_POSTGRES = "postgres"
)
View Source
const (
	CONFIG_TYPE_SIMPLE = iota
	CONFIG_TYPE_ETCD
)
View Source
const (
	DefaultGroup = ""
	TestGroup    = "test"
)

Variables

This section is empty.

Functions

func Entry

func Entry(cluster, table string) bool

func NewMongo

func NewMongo(dbtype, dbname, user, passwd string, addrs []string, timeout time.Duration) (*dbMongo, error)

Types

type Breaker

type Breaker struct {
	Rejected      int32
	RejectedStart int64
	Count         int32
}

func (*Breaker) Run

func (breaker *Breaker) Run()

type BreakerManager

type BreakerManager struct {
	Breakers map[string]*Breaker
	// contains filtered or unexported fields
}

TOOD 简单计数法实现熔断操作,后续改为滑动窗口或三方组件的方式

type Config

type Config struct {
	DBName   string
	DBType   string
	DBAddr   []string
	UserName string
	PassWord string
	TimeOut  time.Duration
}

type Configer

type Configer interface {
	GetConfig(ctx context.Context, instance string) *Config
	GetInstance(ctx context.Context, cluster, table string) (instance string)
	GetConfigByGroup(ctx context.Context, instance, group string) *Config
	GetGroups(ctx context.Context) []string
}

func NewConfiger

func NewConfiger(configType int, data []byte, dbChangeChan chan dbConfigChange) (Configer, error)

func NewEtcdConfiger

func NewEtcdConfiger(ctx context.Context, dbChangeChan chan dbConfigChange) (Configer, error)

func NewSimpleConfiger

func NewSimpleConfiger(data []byte) (Configer, error)

type DB

type DB struct {
	*sqlx.DB
}

func NewDB

func NewDB(sqlxdb *sqlx.DB) *DB

func (*DB) ExecWrapper

func (db *DB) ExecWrapper(tables []interface{}, query string, args ...interface{}) (sql.Result, error)

func (*DB) GetWrapper

func (db *DB) GetWrapper(tables []interface{}, dest interface{}, query string, args ...interface{}) error

func (*DB) NamedExecWrapper

func (db *DB) NamedExecWrapper(tables []interface{}, query string, arg interface{}) (sql.Result, error)

func (*DB) NamedQueryWrapper

func (db *DB) NamedQueryWrapper(tables []interface{}, query string, arg interface{}) (*sqlx.Rows, error)

func (*DB) QueryRowxWrapper

func (db *DB) QueryRowxWrapper(tables []interface{}, query string, args ...interface{}) *sqlx.Row

func (*DB) QueryxWrapper

func (db *DB) QueryxWrapper(tables []interface{}, query string, args ...interface{}) (*sqlx.Rows, error)

func (*DB) SelectWrapper

func (db *DB) SelectWrapper(tables []interface{}, dest interface{}, query string, args ...interface{}) error

type EtcdConfig

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

func (*EtcdConfig) GetConfig

func (m *EtcdConfig) GetConfig(ctx context.Context, instance string) *Config

func (*EtcdConfig) GetConfigByGroup

func (m *EtcdConfig) GetConfigByGroup(ctx context.Context, instance, group string) *Config

func (*EtcdConfig) GetGroups

func (m *EtcdConfig) GetGroups(ctx context.Context) []string

func (*EtcdConfig) GetInstance

func (m *EtcdConfig) GetInstance(ctx context.Context, cluster, table string) (instance string)

type FactoryFunc

type FactoryFunc func(ctx context.Context, key, group string) (in Instancer, err error)

type GormDB

type GormDB struct {
	*gorm.DB
}

func NewGormDB

func NewGormDB(gormdb *gorm.DB) *GormDB

type InstanceManager

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

func NewInstanceManager

func NewInstanceManager(factory FactoryFunc, dbChangeChan chan dbConfigChange, groups []string) *InstanceManager

func (*InstanceManager) Close

func (m *InstanceManager) Close()

func (*InstanceManager) Get

func (m *InstanceManager) Get(ctx context.Context, instance string) Instancer

type Instancer

type Instancer interface {
	GetType() string
	Close() error
}

func Factory

func Factory(ctx context.Context, key, group string, configer Configer) (in Instancer, err error)

type Parser

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

func NewParser

func NewParser(jscfg []byte) (*Parser, error)

func (*Parser) GetConfig

func (m *Parser) GetConfig(instance, group string) *dbInsInfo

func (*Parser) GetInstance

func (m *Parser) GetInstance(cluster, table string) string

func (*Parser) String

func (m *Parser) String() string

type Router

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

func NewRouter

func NewRouter(data []byte) (*Router, error)

func (*Router) MongoExecEventual

func (m *Router) MongoExecEventual(ctx context.Context, cluster, table string, query func(*mgo.Collection) error) error

func (*Router) MongoExecMonotonic

func (m *Router) MongoExecMonotonic(ctx context.Context, cluster, table string, query func(*mgo.Collection) error) error

func (*Router) MongoExecStrong

func (m *Router) MongoExecStrong(ctx context.Context, cluster, table string, query func(*mgo.Collection) error) error

func (*Router) OrmExec

func (m *Router) OrmExec(ctx context.Context, cluster string, query func(*GormDB, []interface{}) error, tables ...string) error

func (*Router) SqlExec

func (m *Router) SqlExec(ctx context.Context, cluster string, query func(*DB, []interface{}) error, tables ...string) error

func (*Router) StatInfo

func (m *Router) StatInfo() []*stat.QueryStat

type SimpleConfig

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

func (*SimpleConfig) GetConfig

func (m *SimpleConfig) GetConfig(ctx context.Context, instance string) *Config

func (*SimpleConfig) GetConfigByGroup

func (m *SimpleConfig) GetConfigByGroup(ctx context.Context, instance, group string) *Config

func (*SimpleConfig) GetGroups

func (m *SimpleConfig) GetGroups(ctx context.Context) []string

func (*SimpleConfig) GetInstance

func (m *SimpleConfig) GetInstance(ctx context.Context, cluster, table string) (instance string)

type Sql

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

func NewSql

func NewSql(dbtype, dbname, addr, userName, passWord string, timeout time.Duration) (*Sql, error)

func (*Sql) Close

func (m *Sql) Close() error

func (*Sql) GetType

func (m *Sql) GetType() string

Jump to

Keyboard shortcuts

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