Documentation
¶
Index ¶
- Constants
- Variables
- func Acceptable(err error) error
- func ErrorIn(err error, errs ...error) bool
- func LoggerCaller(skip int) map[string]string
- func RegisterInterceptor(db *gorm.DB, options *Client, interceptors ...Interceptor)
- type Client
- func (c *Client) ClickHouseDialector() (gorm.Dialector, error)
- func (c *Client) ClickHouseDsn() string
- func (c *Client) Dialector() (gorm.Dialector, error)
- func (c *Client) Dsn() (string, error)
- func (c *Client) MySqlDialector() (gorm.Dialector, error)
- func (c *Client) MySqlDsn() string
- func (c *Client) Open() (*ClientManager, error)
- func (c *Client) PostgreSQLDialector() (gorm.Dialector, error)
- func (c *Client) PostgreSQLDsn() string
- func (c *Client) SqlConn() (*gorm.DB, error)
- type ClientManager
- type Handler
- type Interceptor
- type Option
- func WithCharset(charset string) Option
- func WithDatabase(database string) Option
- func WithDialTimeOut(dialTimeOut string) Option
- func WithDriverName(driverName string) Option
- func WithEnableDebug(disableDebug bool) Option
- func WithEnableMetric(disableMetric bool) Option
- func WithEnableTrace(disableTrace bool) Option
- func WithHost(host string) Option
- func WithMaxIdleConns(maxIdleConns int) Option
- func WithMaxIdleTime(maxIdleTime time.Duration) Option
- func WithMaxLifetime(maxLifetime time.Duration) Option
- func WithMaxOpenConns(maxOpenConns int) Option
- func WithParseTime(parseTime bool) Option
- func WithPassword(password string) Option
- func WithPort(port string) Option
- func WithReadTimeOut(readTimeOut string) Option
- func WithSslMode(sslMode bool) Option
- func WithTimeZone(timeZone string) Option
- func WithUsername(username string) Option
- type Pagination
- type Scope
- type Sort
- type WrapEntry
- func (l *WrapEntry) Error(ctx context.Context, s string, args ...any)
- func (l *WrapEntry) Info(ctx context.Context, s string, args ...any)
- func (l *WrapEntry) LogMode(level logger.LogLevel) logger.Interface
- func (l *WrapEntry) SetDebug(debug bool)
- func (l *WrapEntry) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error)
- func (l *WrapEntry) Warn(ctx context.Context, s string, args ...any)
- type WrapLogger
- func (l *WrapLogger) Error(ctx context.Context, s string, args ...any)
- func (l *WrapLogger) Info(ctx context.Context, s string, args ...any)
- func (l *WrapLogger) LogMode(level logger.LogLevel) logger.Interface
- func (l *WrapLogger) SetDebug(debug bool)
- func (l *WrapLogger) SetSkipErrRecordNotFound(skip bool)
- func (l *WrapLogger) SetSlowThreshold(threshold time.Duration)
- func (l *WrapLogger) SetSourceField(field string)
- func (l *WrapLogger) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error)
- func (l *WrapLogger) Warn(ctx context.Context, s string, args ...any)
Constants ¶
View Source
const ( MySQLDriverName = "mysql" ClickHouseDriverName = "clickhouse" PostgreSQLDriverName = "postgres" TDengineDriverName = "tdengine" )
Variables ¶
View Source
var ( ErrLastInsertIdIsNotSupported = errors.New("LastInsertId is not supported by this driver") ErrRowsAffectedIsNotSupported = errors.New("RowsAffected is not supported by this driver") ErrNoLastInsertIdAvailable = errors.New("no LastInsertId available after DDL statement") ErrNoRowsAffectedAvailable = errors.New("no RowsAffected available after DDL statement") )
Functions ¶
func Acceptable ¶ added in v3.8.18
func LoggerCaller ¶ added in v3.8.17
func RegisterInterceptor ¶ added in v3.8.17
func RegisterInterceptor(db *gorm.DB, options *Client, interceptors ...Interceptor)
Types ¶
type Client ¶
type Client struct {
Host string // 数据库 IP
Port string // 数据库端口
Username string // 数据库用户名
Password string // 数据库密码
Charset string // 数据库字符集
Database string // 数据库名称
ParseTime bool // 是否解析时间
TimeZone string // 数据库时区 mysql & postgresql 专用
SslMode bool // 数据库SSL模式 postgresql 专用
DialTimeOut string // 连接超时时间 clickhouse 专用
ReadTimeOut string // 读取超时时间 clickhouse 专用
MaxIdleConns int // 连接池里最大空闲连接数。必须要比maxOpenConns小
MaxOpenConns int // 连接池最多同时打开的连接数
MaxLifetime time.Duration // 连接池里面的连接最大存活时长
MaxIdleTime time.Duration // 连接池里面的连接最大空闲时长
EnableMetric bool // 开启指标采集
EnableTrace bool // 开启链路追踪
EnableDebug bool // 关闭调试模式
DriverName string // 数据库驱动名称
}
func (*Client) ClickHouseDialector ¶ added in v3.8.17
clickhouse open
func (*Client) ClickHouseDsn ¶ added in v3.8.17
clickhouse Dsn
func (*Client) MySqlDialector ¶ added in v3.8.17
mysql open
func (*Client) PostgreSQLDialector ¶ added in v3.8.17
postgres open
func (*Client) PostgreSQLDsn ¶ added in v3.8.17
postgres Dsn
type ClientManager ¶ added in v3.8.17
func (*ClientManager) Close ¶ added in v3.8.17
func (c *ClientManager) Close() error
func (*ClientManager) Gorm ¶ added in v3.8.17
func (c *ClientManager) Gorm() *gorm.DB
type Interceptor ¶ added in v3.8.17
func MetricInterceptor ¶ added in v3.8.17
func MetricInterceptor() Interceptor
func TraceInterceptor ¶ added in v3.8.17
func TraceInterceptor() Interceptor
type Option ¶
type Option func(r *Client)
Option 选项
func WithDialTimeOut ¶ added in v3.8.17
WithDialTimeOut 设置连接超时时间
func WithEnableDebug ¶ added in v3.8.21
WithEnableDebug 关闭调试模式
func WithEnableMetric ¶ added in v3.8.21
WithEnableMetric 开启指标采集
func WithEnableTrace ¶ added in v3.8.21
WithEnableTrace 开启链路追踪
func WithMaxIdleConns ¶
WithMaxIdleConns 设置连接池里最大空闲连接数
func WithMaxIdleTime ¶
WithMaxIdleTime 设置连接池里面的连接最大空闲时长
func WithMaxLifetime ¶
WithMaxLifetime 设置连接池里面的连接最大存活时长
func WithMaxOpenConns ¶
WithMaxOpenConns 设置连接池最多同时打开的连接数
func WithReadTimeOut ¶ added in v3.8.17
WithReadTimeOut 设置读取超时时间
type Pagination ¶ added in v3.7.25
func (*Pagination) GetLimit ¶ added in v3.7.25
func (obj *Pagination) GetLimit() (int64, error)
func (*Pagination) GetOffset ¶ added in v3.7.25
func (obj *Pagination) GetOffset() (int64, error)
type Scope ¶ added in v3.8.21
func (*Scope) GetEndFloat64 ¶ added in v3.8.21
func (*Scope) GetEndInt64 ¶ added in v3.8.21
func (*Scope) GetEndString ¶ added in v3.8.21
func (*Scope) GetStartFloat64 ¶ added in v3.8.21
func (*Scope) GetStartInt64 ¶ added in v3.8.21
func (*Scope) GetStartString ¶ added in v3.8.21
type WrapEntry ¶ added in v3.8.17
type WrapEntry struct {
Logrus *logrus.Entry
SlowThreshold time.Duration
SourceField string
SkipErrRecordNotFound bool
Debug bool
}
type WrapLogger ¶ added in v3.8.17
type WrapLogger struct {
Logrus *logrus.Logger
SlowThreshold time.Duration
SourceField string
SkipErrRecordNotFound bool
Debug bool
}
func NewLogger ¶ added in v3.8.17
func NewLogger(logger *logrus.Logger) *WrapLogger
func (*WrapLogger) Error ¶ added in v3.8.17
func (l *WrapLogger) Error(ctx context.Context, s string, args ...any)
func (*WrapLogger) Info ¶ added in v3.8.17
func (l *WrapLogger) Info(ctx context.Context, s string, args ...any)
func (*WrapLogger) LogMode ¶ added in v3.8.17
func (l *WrapLogger) LogMode(level logger.LogLevel) logger.Interface
func (*WrapLogger) SetDebug ¶ added in v3.8.17
func (l *WrapLogger) SetDebug(debug bool)
func (*WrapLogger) SetSkipErrRecordNotFound ¶ added in v3.8.17
func (l *WrapLogger) SetSkipErrRecordNotFound(skip bool)
func (*WrapLogger) SetSlowThreshold ¶ added in v3.8.17
func (l *WrapLogger) SetSlowThreshold(threshold time.Duration)
func (*WrapLogger) SetSourceField ¶ added in v3.8.17
func (l *WrapLogger) SetSourceField(field string)
Click to show internal directories.
Click to hide internal directories.