Documentation
¶
Index ¶
- Variables
- func IsErrDuplicatedKey(err error) bool
- func IsErrRecordNotFound(err error) bool
- func NewTxMaker(ori Tx, factory TxFactory) (Tx, *TxMaker)
- func Open(config *Config) (conn *gorm.DB, err error)
- type ClickhouseTable
- type Config
- type DBClient
- func (client *DBClient) DB() *gorm.DB
- func (client *DBClient) DropTables(tables []any) error
- func (client *DBClient) GetConfig() *Config
- func (client *DBClient) NewTx() *gorm.DB
- func (client *DBClient) NewTxMaker(tx Tx) (Tx, *TxMaker)
- func (client *DBClient) Session() *gorm.DB
- func (client *DBClient) Stats() (sql.DBStats, error)
- func (client *DBClient) SyncTables(tables []any) error
- func (client *DBClient) TruncateTables(tables []any) error
- func (client *DBClient) WithDB(db *gorm.DB) *DBClient
- type DBClientOptions
- type DataBaseOption
- type DefaultClickHouseDistributedTable
- type DefaultClickHouseTable
- type DefaultMySQLTable
- type MySQLTable
- type TableOption
- type Tx
- type TxFactory
- type TxMaker
Constants ¶
This section is empty.
Variables ¶
var LogLevelMap = map[string]logger.LogLevel{ "warn": logger.Warn, "info": logger.Info, "error": logger.Error, "silent": logger.Silent, }
LogLevelMap log level for config string.
Functions ¶
func IsErrDuplicatedKey ¶
IsErrDuplicatedKey return true if the error is a duplicate key error @Description: 判断err是否是"主键冲突"
func IsErrRecordNotFound ¶
IsRecordNotFound ... @Description: 判断err是否是"没有该记录"
func NewTxMaker ¶
NewTxMaker new transaction maker.
if ori is nil, create a new transaction by factory if ori is not nil, use the ori transaction function return the new transaction and the txmaker
txmaker is used to manage the transaction lifecycle when the function ends, txmaker.Close(*errp) will be called, the transaction will be committed or rolled back if errp is nil, the transaction will be committed if errp is not nil, the transaction will be rolled back
you can use TxMaker to pass the transaction between functions.
Types ¶
type ClickhouseTable ¶
type ClickhouseTable interface {
ClickhouseTableOption(option DataBaseOption) TableOption
}
ClickhouseTable clickhouse table interface.
type Config ¶
type Config struct {
DSN string `json:"dsn" yaml:"dsn"` // 数据库连接字符串
MaxOpenConns int `json:"max_open_conns" yaml:"max_open_conns"`
MaxIdleConns int `json:"max_idle_conns" yaml:"max_idle_conns"`
MaxIdleTime string `json:"max_idle_time" yaml:"max_idle_time"` // 连接池最大空闲时间
LogLevel string `json:"log_level" yaml:"log_level"` // 日志级别
Cluster string `json:"cluster" yaml:"cluster"` // 集群名称
}
Config DBClient配置.
func ParseConfig ¶
func ParseConfig(conf config.AccessPoint) (config *Config, err error)
ParseConfig Parse config from accesspoint.
type DBClient ¶
type DBClient struct {
// contains filtered or unexported fields
}
DBClient Gorm的数据库连接.
func NewDBClient ¶
NewDBClient Create DBEngine instance.
func (*DBClient) DropTables ¶
DropTables drop tables from db.
func (*DBClient) NewTxMaker ¶
NewTxMaker create a tx maker.
func (*DBClient) SyncTables ¶
SyncTables sync tables defined in table object.
func (*DBClient) TruncateTables ¶
type DBClientOptions ¶
type DBClientOptions struct {
MaxOpenConns int
MaxIdleConns int
MaxIdleTime string
LogLevel string
Cluster string
}
DBClientOptions DBClient 配置选项.
type DataBaseOption ¶
type DefaultClickHouseDistributedTable ¶
type DefaultClickHouseDistributedTable struct {
// 采集时间
Time time.Time `json:"time" gorm:"comment:时序时间"`
}
DefaultClickHouseDistributedTable default clickhouse table field.
func (DefaultClickHouseDistributedTable) ClickhouseTableOption ¶
func (table DefaultClickHouseDistributedTable) ClickhouseTableOption(dbop DataBaseOption) TableOption
ClickhouseTableOption 配置Clickhouse的创建options.
type DefaultClickHouseTable ¶
DefaultClickHouseTable 默认clickhouse表.
func (DefaultClickHouseTable) ClickhouseTableOption ¶
func (table DefaultClickHouseTable) ClickhouseTableOption(dbop DataBaseOption) TableOption
ClickhouseTableOption gorm.
type DefaultMySQLTable ¶
type DefaultMySQLTable struct{}
DefaultMySQLTable default mysql table field.
func (DefaultMySQLTable) MySQLTableOption ¶
func (table DefaultMySQLTable) MySQLTableOption(_ string) TableOption
MySQLTableOption gorm mysql option.
type MySQLTable ¶
type MySQLTable interface {
MySQLTableOption(option DataBaseOption) TableOption
}
MySQLTable mysql table interface.
type TableOption ¶
type TableOption struct {
TableOptions string
// TableClusterOptions for clickhouse distributed table.
TableClusterOptions string
}
TableOption table option.
type TxFactory ¶
type TxFactory interface {
// NewTx create a new transaction
NewTx() Tx
}
TxFactory a factory can create new transaction
type TxMaker ¶
type TxMaker struct {
// contains filtered or unexported fields
}
TxMaker ....
func (*TxMaker) Close ¶
Close close transaction
if origin tx != nil, it means the tx is used by upper function, so we don't need to do anything if origin tx is nil, it means the tx is a new tx created by factory, we need to handle it. if errp is nil, the transaction will be committed if errp is not nil, the transaction will be rolled back