Documentation
¶
Index ¶
- func DB(dbName ...string) xqi.Database
- func DefaultLogger() func(e DbConn)
- func NewDbLoggerPlugin(o *LogOption, log xlogger.ILogger) func(e DbConn)
- type LogLevel
- type LogOption
- type TBaseDb
- func (db *TBaseDb) BeginTran() exception.IException
- func (db *TBaseDb) Close()
- func (db *TBaseDb) Commit() exception.IException
- func (db *TBaseDb) Connection(conf ...interface{}) exception.IException
- func (db *TBaseDb) Execute(szSql string, args ...interface{}) (int64, exception.IException)
- func (db *TBaseDb) GetConn() DbConn
- func (db *TBaseDb) GetErr() exception.IException
- func (db *TBaseDb) LastInsertId() int64
- func (db *TBaseDb) LastSql() string
- func (db *TBaseDb) LastSqlDuration() time.Duration
- func (db *TBaseDb) Query(binder TBinderName, szSql string, args ...interface{}) (result interface{}, err exception.IException)
- func (db *TBaseDb) QueryBind(binder DbQueryBinder, szSql string, args ...interface{}) (result interface{}, err exception.IException)
- func (db *TBaseDb) Rollback() exception.IException
- func (db *TBaseDb) This() interface{}
- func (db *TBaseDb) Transaction(closers ...func(session BasicDB) error) exception.IException
- func (db *TBaseDb) Use(closers ...func(e xqi.DbConn))
- type TDatabase
- type TDbBaseConfig
- func (cfg *TDbBaseConfig) Driver() string
- func (cfg *TDbBaseConfig) Dsn() string
- func (cfg *TDbBaseConfig) LoadFromMap(c map[string]interface{})
- func (cfg *TDbBaseConfig) MaxIdleCons() int
- func (cfg *TDbBaseConfig) MaxOpenCons() int
- func (cfg *TDbBaseConfig) Prefix() string
- func (cfg *TDbBaseConfig) SetDSN(dsn string)
- func (cfg *TDbBaseConfig) SetDriver(driver string)
- func (cfg *TDbBaseConfig) SetMaxIdleCons(v int)
- func (cfg *TDbBaseConfig) SetMaxOpenCons(v int)
- func (cfg *TDbBaseConfig) SetPrefix(prefix string)
- func (cfg *TDbBaseConfig) String() string
- func (cfg *TDbBaseConfig) This() interface{}
- type TDbConfigCluster
- func (dcc *TDbConfigCluster) AddMaster(config DbConfig) DbConfigCluster
- func (dcc *TDbConfigCluster) AddSlave(config DbConfig) DbConfigCluster
- func (dcc *TDbConfigCluster) Driver() string
- func (dcc *TDbConfigCluster) Master() []DbConfig
- func (dcc *TDbConfigCluster) Prefix() string
- func (dcc *TDbConfigCluster) SetDriver(driver string)
- func (dcc *TDbConfigCluster) SetPrefix(prefix string)
- func (dcc *TDbConfigCluster) Slave() []DbConfig
- func (dcc *TDbConfigCluster) String() string
- func (dcc *TDbConfigCluster) This() interface{}
- type TDbConn
- func (c *TDbConn) GetDriver() string
- func (c *TDbConn) GetExecuteDB() *sql.DB
- func (c *TDbConn) GetLogger() DbLogger
- func (c *TDbConn) GetPrefix() string
- func (c *TDbConn) GetQueryDB() *sql.DB
- func (c *TDbConn) Ping() exception.IException
- func (c *TDbConn) SetLogger(logger DbLogger)
- func (c *TDbConn) SetPrefix(pre string)
- func (c *TDbConn) This() interface{}
- func (c *TDbConn) Use(closers ...func(e DbConn))
- type TDbLogger
- func (l *TDbLogger) EnableErrorLog() bool
- func (l *TDbLogger) EnableSlowLog() float64
- func (l *TDbLogger) EnableSqlLog() bool
- func (l *TDbLogger) Error(msg string)
- func (l *TDbLogger) GetLogger() xlogger.ILogger
- func (l *TDbLogger) SetLogger(logger xlogger.ILogger)
- func (l *TDbLogger) Slow(sqlStr string, runtime time.Duration)
- func (l *TDbLogger) Sql(sqlStr string, runtime time.Duration)
- func (l *TDbLogger) This() interface{}
- type TDbMysqlConfig
- func (cfg *TDbMysqlConfig) AddParam(name string, value string) DbMysqlConfig
- func (cfg *TDbMysqlConfig) Charset() string
- func (cfg *TDbMysqlConfig) DbConfig() DbConfig
- func (cfg *TDbMysqlConfig) DbName() string
- func (cfg *TDbMysqlConfig) Dsn() string
- func (cfg *TDbMysqlConfig) Host() string
- func (cfg *TDbMysqlConfig) LoadFromMap(c map[string]interface{})
- func (cfg *TDbMysqlConfig) Params() map[string]string
- func (cfg *TDbMysqlConfig) ParseTime() bool
- func (cfg *TDbMysqlConfig) Password() string
- func (cfg *TDbMysqlConfig) Port() int
- func (cfg *TDbMysqlConfig) Protocol() string
- func (cfg *TDbMysqlConfig) SetCharset(charset string) DbMysqlConfig
- func (cfg *TDbMysqlConfig) SetDatabase(db string) DbMysqlConfig
- func (cfg *TDbMysqlConfig) SetDbName(dbName string)
- func (cfg *TDbMysqlConfig) SetHost(host string)
- func (cfg *TDbMysqlConfig) SetOption(host string, port int, user string, password string, db string, ...) DbMysqlConfig
- func (cfg *TDbMysqlConfig) SetParseTime(b bool) DbMysqlConfig
- func (cfg *TDbMysqlConfig) SetPassword(pwd string)
- func (cfg *TDbMysqlConfig) SetPort(port int)
- func (cfg *TDbMysqlConfig) SetProtocol(protocol string)
- func (cfg *TDbMysqlConfig) SetUser(user string)
- func (cfg *TDbMysqlConfig) User() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultLogger ¶
func DefaultLogger() func(e DbConn)
func NewDbLoggerPlugin ¶
日志插件
Types ¶
type LogOption ¶
type LogOption struct { EnableSqlLog bool // 是否记录慢查询, 默认0s, 不记录, 设置记录的时间阀值, 比如 1, 则表示超过1s的都记录 EnableSlowLog float64 EnableErrorLog bool }
func NewDbLogOptions ¶
func NewDbLogOptions() *LogOption
type TBaseDb ¶
type TBaseDb struct {
// contains filtered or unexported fields
}
func (*TBaseDb) BeginTran ¶
func (db *TBaseDb) BeginTran() exception.IException
func (*TBaseDb) Commit ¶
func (db *TBaseDb) Commit() exception.IException
func (*TBaseDb) Connection ¶
func (db *TBaseDb) Connection(conf ...interface{}) exception.IException
func (*TBaseDb) Execute ¶
func (db *TBaseDb) Execute(szSql string, args ...interface{}) (int64, exception.IException)
func (*TBaseDb) GetErr ¶
func (db *TBaseDb) GetErr() exception.IException
func (*TBaseDb) LastInsertId ¶
func (*TBaseDb) LastSqlDuration ¶
func (*TBaseDb) Query ¶
func (db *TBaseDb) Query(binder TBinderName, szSql string, args ...interface{}) (result interface{}, err exception.IException)
func (*TBaseDb) QueryBind ¶
func (db *TBaseDb) QueryBind(binder DbQueryBinder, szSql string, args ...interface{}) (result interface{}, err exception.IException)
func (*TBaseDb) Rollback ¶
func (db *TBaseDb) Rollback() exception.IException
func (*TBaseDb) Transaction ¶
func (db *TBaseDb) Transaction(closers ...func(session BasicDB) error) exception.IException
type TDbBaseConfig ¶
type TDbBaseConfig struct {
// contains filtered or unexported fields
}
func NewBaseConfig ¶
func NewBaseConfig(driver, dsn string, maxOpenCons, maxIdleCons int, prefix string, inherited ...interface{}) *TDbBaseConfig
func (*TDbBaseConfig) Driver ¶
func (cfg *TDbBaseConfig) Driver() string
func (*TDbBaseConfig) Dsn ¶
func (cfg *TDbBaseConfig) Dsn() string
func (*TDbBaseConfig) LoadFromMap ¶
func (cfg *TDbBaseConfig) LoadFromMap(c map[string]interface{})
func (*TDbBaseConfig) MaxIdleCons ¶
func (cfg *TDbBaseConfig) MaxIdleCons() int
func (*TDbBaseConfig) MaxOpenCons ¶
func (cfg *TDbBaseConfig) MaxOpenCons() int
func (*TDbBaseConfig) Prefix ¶
func (cfg *TDbBaseConfig) Prefix() string
func (*TDbBaseConfig) SetDSN ¶ added in v1.0.1
func (cfg *TDbBaseConfig) SetDSN(dsn string)
func (*TDbBaseConfig) SetDriver ¶ added in v1.0.1
func (cfg *TDbBaseConfig) SetDriver(driver string)
func (*TDbBaseConfig) SetMaxIdleCons ¶ added in v1.0.1
func (cfg *TDbBaseConfig) SetMaxIdleCons(v int)
func (*TDbBaseConfig) SetMaxOpenCons ¶ added in v1.0.1
func (cfg *TDbBaseConfig) SetMaxOpenCons(v int)
func (*TDbBaseConfig) SetPrefix ¶ added in v1.0.1
func (cfg *TDbBaseConfig) SetPrefix(prefix string)
func (*TDbBaseConfig) String ¶
func (cfg *TDbBaseConfig) String() string
func (*TDbBaseConfig) This ¶
func (cfg *TDbBaseConfig) This() interface{}
type TDbConfigCluster ¶
type TDbConfigCluster struct {
// contains filtered or unexported fields
}
func NewDbConfigCluster ¶
func NewDbConfigCluster() *TDbConfigCluster
func (*TDbConfigCluster) AddMaster ¶
func (dcc *TDbConfigCluster) AddMaster(config DbConfig) DbConfigCluster
func (*TDbConfigCluster) AddSlave ¶
func (dcc *TDbConfigCluster) AddSlave(config DbConfig) DbConfigCluster
func (*TDbConfigCluster) Driver ¶
func (dcc *TDbConfigCluster) Driver() string
func (*TDbConfigCluster) Master ¶
func (dcc *TDbConfigCluster) Master() []DbConfig
func (*TDbConfigCluster) Prefix ¶
func (dcc *TDbConfigCluster) Prefix() string
func (*TDbConfigCluster) SetDriver ¶ added in v1.0.1
func (dcc *TDbConfigCluster) SetDriver(driver string)
func (*TDbConfigCluster) SetPrefix ¶ added in v1.0.1
func (dcc *TDbConfigCluster) SetPrefix(prefix string)
func (*TDbConfigCluster) Slave ¶
func (dcc *TDbConfigCluster) Slave() []DbConfig
func (*TDbConfigCluster) String ¶
func (dcc *TDbConfigCluster) String() string
func (*TDbConfigCluster) This ¶
func (dcc *TDbConfigCluster) This() interface{}
type TDbConn ¶
type TDbConn struct {
// contains filtered or unexported fields
}
func NewDbConn ¶
func NewDbConn(conf ...interface{}) (conn *TDbConn, err exception.IException)
NewDbConn : 初始化 TDbConn 结构体对象指针
func (*TDbConn) GetExecuteDB ¶
GetExecuteDB : 获取一个主库用来做查询之外的操作
func (*TDbConn) GetQueryDB ¶
GetQueryDB : get a slave db for using query operation GetQueryDB : 获取一个从库用来做查询操作
type TDbLogger ¶
type TDbLogger struct {
// contains filtered or unexported fields
}
func (*TDbLogger) EnableErrorLog ¶
func (*TDbLogger) EnableSlowLog ¶
func (*TDbLogger) EnableSqlLog ¶
type TDbMysqlConfig ¶
type TDbMysqlConfig struct { *TDbBaseConfig // contains filtered or unexported fields }
func NewMysqlConfig ¶
func NewMysqlConfig() *TDbMysqlConfig
func NewMysqlConfig6 ¶
func NewMysqlConfig6(host string, port int, user string, password string, db string, protocol ...string) *TDbMysqlConfig
创建数据库配置
func NewMysqlConfigFromMap ¶
func NewMysqlConfigFromMap(c map[string]interface{}) *TDbMysqlConfig
从配置文件创建数据库配置
func (*TDbMysqlConfig) AddParam ¶
func (cfg *TDbMysqlConfig) AddParam(name string, value string) DbMysqlConfig
func (*TDbMysqlConfig) DbConfig ¶
func (cfg *TDbMysqlConfig) DbConfig() DbConfig
func (*TDbMysqlConfig) Dsn ¶
func (cfg *TDbMysqlConfig) Dsn() string
mysql 示例: root:root@tcp(localhost:3306)/test?charset=utf8&parseTime=true
func (*TDbMysqlConfig) LoadFromMap ¶
func (cfg *TDbMysqlConfig) LoadFromMap(c map[string]interface{})
func (*TDbMysqlConfig) Protocol ¶
func (cfg *TDbMysqlConfig) Protocol() string
func (*TDbMysqlConfig) SetCharset ¶
func (cfg *TDbMysqlConfig) SetCharset(charset string) DbMysqlConfig
func (*TDbMysqlConfig) SetDatabase ¶
func (cfg *TDbMysqlConfig) SetDatabase(db string) DbMysqlConfig
func (*TDbMysqlConfig) SetDbName ¶ added in v1.0.1
func (cfg *TDbMysqlConfig) SetDbName(dbName string)
func (*TDbMysqlConfig) SetHost ¶ added in v1.0.1
func (cfg *TDbMysqlConfig) SetHost(host string)
func (*TDbMysqlConfig) SetParseTime ¶
func (cfg *TDbMysqlConfig) SetParseTime(b bool) DbMysqlConfig
func (*TDbMysqlConfig) SetPassword ¶ added in v1.0.1
func (cfg *TDbMysqlConfig) SetPassword(pwd string)
func (*TDbMysqlConfig) SetPort ¶ added in v1.0.1
func (cfg *TDbMysqlConfig) SetPort(port int)
func (*TDbMysqlConfig) SetProtocol ¶ added in v1.0.1
func (cfg *TDbMysqlConfig) SetProtocol(protocol string)
func (*TDbMysqlConfig) SetUser ¶ added in v1.0.1
func (cfg *TDbMysqlConfig) SetUser(user string)
Click to show internal directories.
Click to hide internal directories.