Documentation
¶
Index ¶
- Constants
- func GetDBDefault(ctx context.Context) (msql.XDBWrapper, error)
- func GetSettingFunctionList(dynamicConfigure *msql.DynamicConf) []msql.Setting
- func InitDBConf(ctx context.Context, confCenter mconfig.ConfigCenter) error
- func IsReloadConn(key string) bool
- func New(dbName, user, password, host string) *msql.Option
- func NewManager() msql.ManagerProxy
- func OrmExecDefault(ctx context.Context, query func(*GormDB, []interface{}) error, ...) error
- func ReloadDBConf(ctx context.Context, confCenter mconfig.ConfigCenter, ...) error
- func SetAllowAllFiles(ok bool) msql.Setting
- func SetAllowCleartextPasswords(ok bool) msql.Setting
- func SetAllowNativePasswords(ok bool) msql.Setting
- func SetAutoCommit(ok bool) msql.Setting
- func SetCharset(v string) msql.Setting
- func SetClientFoundRows(ok bool) msql.Setting
- func SetCollation(v string) msql.Setting
- func SetColumnsWithAlias(ok bool) msql.Setting
- func SetInterpolateParams(ok bool) msql.Setting
- func SetLoc(v string) msql.Setting
- func SetParseTime(ok bool) msql.Setting
- func SetReadTimeout(timeout time.Duration) msql.Setting
- func SetStrict(ok bool) msql.Setting
- func SetTimeout(timeout time.Duration) msql.Setting
- func SetWriteTimeout(timeout time.Duration) msql.Setting
- func SqlExecDefault(ctx context.Context, query func(*DBX, []interface{}) error, tables ...string) error
- type DB
- func (db *DB) BeginTx(ctx context.Context) (*Tx, error)
- func (db *DB) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
- func (db *DB) GetDb() *sql.DB
- func (db *DB) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
- func (db *DB) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
- func (db *DB) SetSqlDB(outDb *sql.DB)
- func (db *DB) TxExecute(ctx context.Context, exec func(db msql.XDB) error) error
- type DBInstance
- type DBX
- func (db *DBX) ExecWrapper(tables []interface{}, query string, args ...interface{}) (sql.Result, error)
- func (db *DBX) GetWrapper(tables []interface{}, dest interface{}, query string, args ...interface{}) error
- func (db *DBX) NamedExecWrapper(tables []interface{}, query string, arg interface{}) (sql.Result, error)
- func (db *DBX) NamedQueryWrapper(tables []interface{}, query string, arg interface{}) (*sqlx.Rows, error)
- func (db *DBX) QueryRowxWrapper(tables []interface{}, query string, args ...interface{}) *sqlx.Row
- func (db *DBX) QueryxWrapper(tables []interface{}, query string, args ...interface{}) (*sqlx.Rows, error)
- func (db *DBX) SelectWrapper(tables []interface{}, dest interface{}, query string, args ...interface{}) error
- type DbManagerSelector
- func (m *DbManagerSelector) GetDBDefault(ctx context.Context) (db msql.XDBWrapper, err error)
- func (m *DbManagerSelector) InitDbManagerConf(ctx context.Context, configCenter mconfig.ConfigCenter) error
- func (m *DbManagerSelector) ReloadDbManagerConf(ctx context.Context, configCenter mconfig.ConfigCenter, ...) error
- type DbManagerSelectorConfiger
- type DynamicConfigure
- type GormDB
- type InstanceKey
- type Manager
- func (m *Manager) GetDB(ctx context.Context, insName, dbName string) (msql.XDBWrapper, error)
- func (m *Manager) GetInstance(insName, dbName string) (msql.DBInstanceProxy, error)
- func (m *Manager) InitConf(ctx context.Context, confCenter mconfig.ConfigCenter) error
- func (m *Manager) ReloadConf(ctx context.Context, config mconfig.ConfigCenter, event mobserver.ChangeEvent) error
- type ProxyAddr
- type Tx
- func (tx *Tx) Commit(ctx context.Context) error
- func (tx *Tx) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
- func (tx *Tx) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
- func (tx *Tx) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
- func (tx *Tx) Rollback(ctx context.Context) error
Constants ¶
const ( ConfigFromApollo configType = iota ConfigFromEnv ConfigFromYaml )
const (
DB_TYPE_MYSQL = "mysql"
)
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 OrmExecDefault ¶
func ReloadDBConf ¶
func ReloadDBConf(ctx context.Context, confCenter mconfig.ConfigCenter, event mobserver.ChangeEvent) error
ReloadDBConf reload db conf when change
func SetAllowAllFiles ¶
SetAllowAllFiles allowAllFiles=true disables the file Whitelist for LOAD DATA LOCAL INFILE and allows all files. Might be insecure!
func SetAllowCleartextPasswords ¶
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 ¶
SetAllowNativePasswords allows the usage of the mysql native password method
func SetAutoCommit ¶
SetAutoCommit set it to true if you know what you are doing
func SetCharset ¶
SetCharset Sets the charset used for client-server interaction
func SetClientFoundRows ¶
SetClientFoundRows clientFoundRows=true causes an UPDATE to return the number of matching rows instead of the number of rows changed.
func SetCollation ¶
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 ¶
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 ¶
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 ¶
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 ¶
SetParseTime parseTime=true changes the output type of DATE and DATETIME values to time.Time instead of []byte / string
func SetReadTimeout ¶
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 ¶
SetStrict strict=true enables the strict mode in which MySQL warnings are treated as errors.
func SetTimeout ¶
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 ¶
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".
Types ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB 实现了XDB接口,同时可以通过GetTx获取一个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) 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 ¶
QueryRowContext executes a query that is expected to return at most one row.
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) GetDB ¶
func (m *DBInstance) GetDB() *sql.DB
func (*DBInstance) GetDbName ¶
func (m *DBInstance) GetDbName() string
type DBX ¶
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 ¶
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 ...
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) GetInstance ¶
func (m *Manager) GetInstance(insName, dbName string) (msql.DBInstanceProxy, error)
func (*Manager) ReloadConf ¶
func (m *Manager) ReloadConf(ctx context.Context, config mconfig.ConfigCenter, event mobserver.ChangeEvent) error
type Tx ¶
type Tx struct {
// contains filtered or unexported fields
}
Tx wrapper of sql.Tx
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 ¶
QueryRowContext executes a query that is expected to return at most one row.