xmanager

package
v0.0.0-...-9b4f9b9 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2025 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConfigFromApollo configType = iota
	ConfigFromEnv
	ConfigFromYaml
)
View Source
const (
	DB_TYPE_MYSQL = "mysql"
)
View Source
const (
	WeirCluster = "weir"
)

Variables

This section is empty.

Functions

func GetDBDefault

func GetDBDefault(ctx context.Context) (msql.XDBWrapper, error)

GetDBDefault generalization of GetDB in Manager

func GetSettingFunctionList

func GetSettingFunctionList(dynamicConfigure *msql.DynamicConf) []msql.Setting

func InitDBConf

func InitDBConf(ctx context.Context, confCenter mconfig.ConfigCenter) error

InitDBConf init db dynamic conf

func IsReloadConn

func IsReloadConn(key string) bool

func New

func New(dbName, user, password, host string) *msql.Option

New returns an Option

func NewManager

func NewManager() msql.ManagerProxy

NewManager 实例化DB路由对象

func OrmExecDefault

func OrmExecDefault(ctx context.Context, query func(*GormDB, []interface{}) error, tables ...string) error

func ReloadDBConf

func ReloadDBConf(ctx context.Context, confCenter mconfig.ConfigCenter, event mobserver.ChangeEvent) error

ReloadDBConf reload db conf when change

func SetAllowAllFiles

func SetAllowAllFiles(ok bool) msql.Setting

SetAllowAllFiles allowAllFiles=true disables the file Whitelist for LOAD DATA LOCAL INFILE and allows all files. Might be insecure!

func SetAllowCleartextPasswords

func SetAllowCleartextPasswords(ok bool) msql.Setting

SetAllowCleartextPasswords allowCleartextPasswords=true allows using the cleartext client side plugin if required by an account, such as one defined with the PAM authentication plugin. Sending passwords in clear text may be a security problem in some configurations.

func SetAllowNativePasswords

func SetAllowNativePasswords(ok bool) msql.Setting

SetAllowNativePasswords allows the usage of the mysql native password method

func SetAutoCommit

func SetAutoCommit(ok bool) msql.Setting

SetAutoCommit set it to true if you know what you are doing

func SetCharset

func SetCharset(v string) msql.Setting

SetCharset Sets the charset used for client-server interaction

func SetClientFoundRows

func SetClientFoundRows(ok bool) msql.Setting

SetClientFoundRows clientFoundRows=true causes an UPDATE to return the number of matching rows instead of the number of rows changed.

func SetCollation

func SetCollation(v string) msql.Setting

SetCollation Sets the collation used for client-server interaction on connection. In contrast to charset, collation does not issue additional queries. If the specified collation is unavailable on the target server, the connection will fail.

func SetColumnsWithAlias

func SetColumnsWithAlias(ok bool) msql.Setting

SetColumnsWithAlias When columnsWithAlias is true, calls to sql.Rows.Columns() will return the table alias and the column name separated by a dot.

func SetInterpolateParams

func SetInterpolateParams(ok bool) msql.Setting

SetInterpolateParams If interpolateParams is true, placeholders (?) in calls to db.Query() and db.Exec() are interpolated into a single query string with given parameters. This reduces the number of roundtrips, since the driver has to prepare a statement, execute it with given parameters and close the statement again with interpolateParams=false.

func SetLoc

func SetLoc(v string) msql.Setting

SetLoc Sets the location for time.Time values (when using parseTime=true). "Local" sets the system's location. See time.LoadLocation for details.

func SetParseTime

func SetParseTime(ok bool) msql.Setting

SetParseTime parseTime=true changes the output type of DATE and DATETIME values to time.Time instead of []byte / string

func SetReadTimeout

func SetReadTimeout(timeout time.Duration) msql.Setting

SetReadTimeout I/O read timeout. The value must be a decimal number with a unit suffix ( "ms", "s", "m", "h" ), such as "30s", "0.5m" or "1m30s".

func SetStrict

func SetStrict(ok bool) msql.Setting

SetStrict strict=true enables the strict mode in which MySQL warnings are treated as errors.

func SetTimeout

func SetTimeout(timeout time.Duration) msql.Setting

SetTimeout Driver side connection timeout. The value must be a decimal number with an unit suffix ( "ms", "s", "m", "h" ), such as "30s", "0.5m" or "1m30s". To set a server side timeout, use the parameter wait_timeout.

func SetWriteTimeout

func SetWriteTimeout(timeout time.Duration) msql.Setting

SetWriteTimeout I/O write timeout. The value must be a decimal number with a unit suffix ( "ms", "s", "m", "h" ), such as "30s", "0.5m" or "1m30s".

func SqlExecDefault

func SqlExecDefault(ctx context.Context, query func(*DBX, []interface{}) error, tables ...string) error

SqlExecDefault generalization of SqlExec in Manager TODO: set cluster or db metrics param

Types

type DB

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

DB 实现了XDB接口,同时可以通过GetTx获取一个Tx句柄并进行提交

func (*DB) BeginTx

func (db *DB) BeginTx(ctx context.Context) (*Tx, error)

BeginTx return Tx, wrapper of sql.Tx

func (*DB) ExecContext

func (db *DB) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)

ExecContext exec insert/update/delete and so on.

func (*DB) GetDb

func (db *DB) GetDb() *sql.DB

func (*DB) QueryContext

func (db *DB) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)

QueryContext executes a query that returns rows, typically a SELECT.

func (*DB) QueryRowContext

func (db *DB) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row

QueryRowContext executes a query that is expected to return at most one row.

func (*DB) SetSqlDB

func (db *DB) SetSqlDB(outDb *sql.DB)

SetSqlDB mock时使用

func (*DB) TxExecute

func (db *DB) TxExecute(ctx context.Context, exec func(db msql.XDB) error) error

type DBInstance

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

DBInstance ...

func NewDBInstance

func NewDBInstance(addr ProxyAddr, insKey *InstanceKey, dynamicConfigure msql.DynamicConfigureProxy[*msql.Cfg, *msql.DynamicConf]) (*DBInstance, error)

NewDBInstance 实例化DB实例

func (*DBInstance) Close

func (m *DBInstance) Close() error

Close ...

func (*DBInstance) GetDB

func (m *DBInstance) GetDB() *sql.DB

func (*DBInstance) GetDbName

func (m *DBInstance) GetDbName() string

func (*DBInstance) GetType

func (m *DBInstance) GetType() string

GetType ...

func (*DBInstance) Reload

func (m *DBInstance) Reload() error

Reload ...

type DBX

type DBX struct {
	*sqlx.DB
}

DBX mapper dbrouter DB

func (*DBX) ExecWrapper

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

ExecWrapper ...

func (*DBX) GetWrapper

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

GetWrapper ...

func (*DBX) NamedExecWrapper

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

NamedExecWrapper ...

func (*DBX) NamedQueryWrapper

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

NamedQueryWrapper ...

func (*DBX) QueryRowxWrapper

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

QueryRowxWrapper ...

func (*DBX) QueryxWrapper

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

QueryxWrapper ...

func (*DBX) SelectWrapper

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

SelectWrapper ...

type DbManagerSelector

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

func NewDbManagerSelector

func NewDbManagerSelector() (*DbManagerSelector, error)

func (*DbManagerSelector) GetDBDefault

func (m *DbManagerSelector) GetDBDefault(ctx context.Context) (db msql.XDBWrapper, err error)

GetDBDefault in newManager key1: insName, key2: dbname

func (*DbManagerSelector) InitDbManagerConf

func (m *DbManagerSelector) InitDbManagerConf(ctx context.Context, configCenter mconfig.ConfigCenter) error

InitDbManagerConf init db dynamic conf

func (*DbManagerSelector) ReloadDbManagerConf

func (m *DbManagerSelector) ReloadDbManagerConf(ctx context.Context, configCenter mconfig.ConfigCenter, event mobserver.ChangeEvent) error

ReloadDbManagerConf reload db conf when change

type DbManagerSelectorConfiger

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

func NewDbManagerSelectorConfiger

func NewDbManagerSelectorConfiger() *DbManagerSelectorConfiger

func (*DbManagerSelectorConfiger) GetManagerInfo

func (m *DbManagerSelectorConfiger) GetManagerInfo() (key1 string, key2 string)

func (*DbManagerSelectorConfiger) IsInitialized

func (m *DbManagerSelectorConfiger) IsInitialized() bool

type DynamicConfigure

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

DynamicConfigure ...

func (*DynamicConfigure) IsInit

func (c *DynamicConfigure) IsInit() bool

func (*DynamicConfigure) LoadDynamicConf

func (c *DynamicConfigure) LoadDynamicConf(insName string, dynamicConf *msql.DynamicConf)

LoadDynamicConf ...

func (*DynamicConfigure) SetConf

func (c *DynamicConfigure) SetConf(cfg *msql.Cfg)

SetConf ...

type GormDB

type GormDB struct {
	*gorm.DB
}

GormDB ...

type InstanceKey

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

func CreateInstanceKey

func CreateInstanceKey(instanceName, dbName string) (InstanceKey, error)

func (*InstanceKey) GetDbName

func (m *InstanceKey) GetDbName() string

func (*InstanceKey) GetInstanceName

func (m *InstanceKey) GetInstanceName() string

func (*InstanceKey) String

func (m *InstanceKey) String() string

type Manager

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

func (*Manager) GetDB

func (m *Manager) GetDB(ctx context.Context, insName, dbName string) (msql.XDBWrapper, error)

GetDB return xmanager.DB without transaction

func (*Manager) GetInstance

func (m *Manager) GetInstance(insName, dbName string) (msql.DBInstanceProxy, error)

func (*Manager) InitConf

func (m *Manager) InitConf(ctx context.Context, confCenter mconfig.ConfigCenter) error

func (*Manager) ReloadConf

func (m *Manager) ReloadConf(ctx context.Context, config mconfig.ConfigCenter, event mobserver.ChangeEvent) error

type ProxyAddr

type ProxyAddr struct {
	Host string
	Port int
}

ProxyAddr proxy地址

type Tx

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

Tx wrapper of sql.Tx

func (*Tx) Commit

func (tx *Tx) Commit(ctx context.Context) error

Commit wrapper of sql.Tx commit

func (*Tx) ExecContext

func (tx *Tx) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)

ExecContext exec insert/update/delete and so on.

func (*Tx) QueryContext

func (tx *Tx) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)

QueryContext executes a query that returns rows, typically a SELECT.

func (*Tx) QueryRowContext

func (tx *Tx) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row

QueryRowContext executes a query that is expected to return at most one row.

func (*Tx) Rollback

func (tx *Tx) Rollback(ctx context.Context) error

Rollback wrapper of sql.Tx rollback

Jump to

Keyboard shortcuts

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