tsdb

package
v0.25.3 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

* @Author: kamalyes 501893067@qq.com * @Date: 2026-04-23 00:00:00 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2026-04-23 19:58:55 * @FilePath: \go-config\pkg\tsdb\clickhouse.go * @Description: ClickHouse数据库配置 * * Copyright (c) 2026 by kamalyes, All Rights Reserved.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClickHouse

type ClickHouse struct {
	ModuleName                               string `mapstructure:"module-name" yaml:"module-name" json:"moduleName"`                                                    // 模块名称
	Enabled                                  bool   `mapstructure:"enabled" yaml:"enabled" json:"enabled"`                                                               // 是否启用
	Host                                     string `mapstructure:"host" yaml:"host" json:"host"            validate:"required"`                                         // 数据库 IP 地址
	Port                                     string `mapstructure:"port" yaml:"port" json:"port"            validate:"required"`                                         // 端口(原生协议默认9000,HTTP协议默认8123)
	Config                                   string `mapstructure:"config" yaml:"config" json:"config"          validate:"required"`                                     // 后缀配置 例如: dial_timeout=10s&read_timeout=20s
	LogLevel                                 string `mapstructure:"log-level" yaml:"log-level" json:"logLevel"       validate:"required"`                                // SQL 日志等级
	SlowThreshold                            int    `mapstructure:"slow-threshold" yaml:"slow-threshold" json:"slowThreshold"`                                           // 慢查询阈值(毫秒)
	IgnoreRecordNotFoundError                bool   `mapstructure:"ignore-record-not-found-error" yaml:"ignore-record-not-found-error" json:"ignoreRecordNotFoundError"` // 是否忽略ErrRecordNotFound错误
	Dbname                                   string `mapstructure:"db-name" yaml:"db-name" json:"dbName"         validate:"required"`                                    // 数据库名称
	Username                                 string `mapstructure:"username" yaml:"username" json:"username"        validate:"required"`                                 // 数据库用户名
	Password                                 string `mapstructure:"password" yaml:"password" json:"password"`                                                            // 数据库密码(ClickHouse允许为空)
	Protocol                                 string `mapstructure:"protocol" yaml:"protocol" json:"protocol"`                                                            // 协议类型:native(默认)或 http
	Cluster                                  string `mapstructure:"cluster" yaml:"cluster" json:"cluster"`                                                               // ClickHouse集群名称(集群模式使用)
	Compress                                 bool   `mapstructure:"compress" yaml:"compress" json:"compress"`                                                            // 是否启用压缩
	Debug                                    bool   `mapstructure:"debug" yaml:"debug" json:"debug"`                                                                     // 是否启用调试模式
	Secure                                   bool   `mapstructure:"secure" yaml:"secure" json:"secure"`                                                                  // 是否启用TLS安全连接
	DialTimeout                              int    `mapstructure:"dial-timeout" yaml:"dial-timeout" json:"dialTimeout" validate:"min=0"`                                // 连接超时(秒)
	ReadTimeout                              int    `mapstructure:"read-timeout" yaml:"read-timeout" json:"readTimeout" validate:"min=0"`                                // 读取超时(秒)
	MaxIdleConns                             int    `mapstructure:"max-idle-conns" yaml:"max-idle-conns" json:"maxIdleConns"  validate:"min=0"`                          // 最大空闲连接数
	MaxOpenConns                             int    `mapstructure:"max-open-conns" yaml:"max-open-conns" json:"maxOpenConns"  validate:"min=0"`                          // 最大连接数
	ConnMaxIdleTime                          int    `mapstructure:"conn-max-idle-time" yaml:"conn-max-idle-time" json:"connMaxIdleTime" validate:"min=0"`                // 连接最大空闲时间 单位:秒
	ConnMaxLifeTime                          int    `mapstructure:"conn-max-life-time" yaml:"conn-max-life-time" json:"connMaxLifeTime" validate:"min=0"`                // 连接最大生命周期 单位:秒
	SkipDefaultTransaction                   bool   `mapstructure:"skip-default-transaction" yaml:"skip-default-transaction" json:"skipDefaultTransaction"`              // 跳过默认事务
	PrepareStmt                              bool   `mapstructure:"prepare-stmt" yaml:"prepare-stmt" json:"prepareStmt"`                                                 // 预编译语句
	DisableForeignKeyConstraintWhenMigrating bool   ``                                                                                                                   // 禁用自动创建外键约束(ClickHouse不支持外键)
	/* 161-byte string literal not displayed */
	DisableNestedTransaction bool `mapstructure:"disable-nested-transaction" yaml:"disable-nested-transaction" json:"disableNestedTransaction"` // 禁用嵌套事务
	AllowGlobalUpdate        bool `mapstructure:"allow-global-update" yaml:"allow-global-update" json:"allowGlobalUpdate"`                      // 允许全局更新
	QueryFields              bool `mapstructure:"query-fields" yaml:"query-fields" json:"queryFields"`                                          // 执行查询时选择所有字段
	CreateBatchSize          int  `mapstructure:"create-batch-size" yaml:"create-batch-size" json:"createBatchSize"`                            // 批量创建大小
	SingularTable            bool `mapstructure:"singular-table" yaml:"singular-table" json:"singularTable"`                                    // 使用单数表名
}

ClickHouse ClickHouse数据库配置

func DefaultClickHouse

func DefaultClickHouse() *ClickHouse

DefaultClickHouse 创建默认ClickHouse配置

func NewClickHouseConfig

func NewClickHouseConfig(opt *ClickHouse) *ClickHouse

NewClickHouseConfig 创建一个新的ClickHouse配置实例

func (*ClickHouse) Clone

func (c *ClickHouse) Clone() internal.Configurable

func (*ClickHouse) Get

func (c *ClickHouse) Get() interface{}

func (*ClickHouse) GetAllowGlobalUpdate

func (c *ClickHouse) GetAllowGlobalUpdate() bool

func (*ClickHouse) GetConfig

func (c *ClickHouse) GetConfig() string

func (*ClickHouse) GetCreateBatchSize

func (c *ClickHouse) GetCreateBatchSize() int

func (*ClickHouse) GetDBName

func (c *ClickHouse) GetDBName() string

func (*ClickHouse) GetDisableForeignKeyConstraintWhenMigrating

func (c *ClickHouse) GetDisableForeignKeyConstraintWhenMigrating() bool

func (*ClickHouse) GetDisableNestedTransaction

func (c *ClickHouse) GetDisableNestedTransaction() bool

func (*ClickHouse) GetHost

func (c *ClickHouse) GetHost() string

为ClickHouse配置实现DatabaseProvider接口

func (*ClickHouse) GetIgnoreRecordNotFoundError

func (c *ClickHouse) GetIgnoreRecordNotFoundError() bool

func (*ClickHouse) GetModuleName

func (c *ClickHouse) GetModuleName() string

func (*ClickHouse) GetPassword

func (c *ClickHouse) GetPassword() string

func (*ClickHouse) GetPort

func (c *ClickHouse) GetPort() string

func (*ClickHouse) GetPrepareStmt

func (c *ClickHouse) GetPrepareStmt() bool

func (*ClickHouse) GetQueryFields

func (c *ClickHouse) GetQueryFields() bool

func (*ClickHouse) GetSingularTable

func (c *ClickHouse) GetSingularTable() bool

func (*ClickHouse) GetSkipDefaultTransaction

func (c *ClickHouse) GetSkipDefaultTransaction() bool

func (*ClickHouse) GetSlowThreshold

func (c *ClickHouse) GetSlowThreshold() int

func (*ClickHouse) GetUsername

func (c *ClickHouse) GetUsername() string

func (*ClickHouse) IsEnabled

func (c *ClickHouse) IsEnabled() bool

IsEnabled 检查ClickHouse是否启用

func (*ClickHouse) Set

func (c *ClickHouse) Set(data interface{})

func (*ClickHouse) SetCredentials

func (c *ClickHouse) SetCredentials(username, password string)

func (*ClickHouse) SetDBName

func (c *ClickHouse) SetDBName(dbName string)

func (*ClickHouse) SetHost

func (c *ClickHouse) SetHost(host string)

func (*ClickHouse) SetPort

func (c *ClickHouse) SetPort(port string)

func (*ClickHouse) Validate

func (c *ClickHouse) Validate() error

func (*ClickHouse) WithCluster

func (c *ClickHouse) WithCluster(cluster string) *ClickHouse

WithCluster 设置集群名称

func (*ClickHouse) WithCompress

func (c *ClickHouse) WithCompress(compress bool) *ClickHouse

WithCompress 设置是否启用压缩

func (*ClickHouse) WithConfig

func (c *ClickHouse) WithConfig(config string) *ClickHouse

WithConfig 设置数据库配置参数

func (*ClickHouse) WithConnMaxIdleTime

func (c *ClickHouse) WithConnMaxIdleTime(connMaxIdleTime int) *ClickHouse

WithConnMaxIdleTime 设置连接最大空闲时间

func (*ClickHouse) WithConnMaxLifeTime

func (c *ClickHouse) WithConnMaxLifeTime(connMaxLifeTime int) *ClickHouse

WithConnMaxLifeTime 设置连接最大生命周期

func (*ClickHouse) WithDbname

func (c *ClickHouse) WithDbname(dbname string) *ClickHouse

WithDbname 设置数据库名称

func (*ClickHouse) WithDebug

func (c *ClickHouse) WithDebug(debug bool) *ClickHouse

WithDebug 设置是否启用调试模式

func (*ClickHouse) WithDialTimeout

func (c *ClickHouse) WithDialTimeout(dialTimeout int) *ClickHouse

WithDialTimeout 设置连接超时(秒)

func (*ClickHouse) WithEnabled

func (c *ClickHouse) WithEnabled(enabled bool) *ClickHouse

WithEnabled 设置是否启用ClickHouse

func (*ClickHouse) WithHost

func (c *ClickHouse) WithHost(host string) *ClickHouse

WithHost 设置数据库主机地址

func (*ClickHouse) WithLogLevel

func (c *ClickHouse) WithLogLevel(logLevel string) *ClickHouse

WithLogLevel 设置日志级别

func (*ClickHouse) WithMaxIdleConns

func (c *ClickHouse) WithMaxIdleConns(maxIdleConns int) *ClickHouse

WithMaxIdleConns 设置最大空闲连接数

func (*ClickHouse) WithMaxOpenConns

func (c *ClickHouse) WithMaxOpenConns(maxOpenConns int) *ClickHouse

WithMaxOpenConns 设置最大连接数

func (*ClickHouse) WithModuleName

func (c *ClickHouse) WithModuleName(moduleName string) *ClickHouse

WithModuleName 设置模块名称

func (*ClickHouse) WithPassword

func (c *ClickHouse) WithPassword(password string) *ClickHouse

WithPassword 设置数据库密码

func (*ClickHouse) WithPort

func (c *ClickHouse) WithPort(port string) *ClickHouse

WithPort 设置数据库端口

func (*ClickHouse) WithProtocol

func (c *ClickHouse) WithProtocol(protocol string) *ClickHouse

WithProtocol 设置通信协议 (native 或 http)

func (*ClickHouse) WithReadTimeout

func (c *ClickHouse) WithReadTimeout(readTimeout int) *ClickHouse

WithReadTimeout 设置读取超时(秒)

func (*ClickHouse) WithSecure

func (c *ClickHouse) WithSecure(secure bool) *ClickHouse

WithSecure 设置是否启用TLS安全连接

func (*ClickHouse) WithUsername

func (c *ClickHouse) WithUsername(username string) *ClickHouse

WithUsername 设置数据库用户名

Jump to

Keyboard shortcuts

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