Documentation
¶
Index ¶
- type ClickHouseClient
- func (c *ClickHouseClient) Close() error
- func (c *ClickHouseClient) Exec(ctx context.Context, query string, args ...interface{}) error
- func (c *ClickHouseClient) GetConn() driver.Conn
- func (c *ClickHouseClient) GetDB() *sql.DB
- func (c *ClickHouseClient) Insert(ctx context.Context, table string, columns []string, rows [][]interface{}) error
- func (c *ClickHouseClient) Ping(ctx context.Context) error
- func (c *ClickHouseClient) Query(ctx context.Context, query string, args ...interface{}) (driver.Rows, error)
- func (c *ClickHouseClient) QueryRow(ctx context.Context, query string, args ...interface{}) driver.Row
- type Config
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ClickHouseClient ¶
type ClickHouseClient struct {
EnableTrace bool // 是否启用追踪
// contains filtered or unexported fields
}
ClickHouseClient ClickHouse 客户端接口,包含连接
func NewClickHouse ¶
func NewClickHouse(opts *Options) (*ClickHouseClient, error)
NewClickHouse 根据给定的选项创建一个新的 ClickHouse 客户端实例
func (*ClickHouseClient) Exec ¶
func (c *ClickHouseClient) Exec(ctx context.Context, query string, args ...interface{}) error
Exec 执行 SQL 语句(不返回结果集,自动处理追踪)
func (*ClickHouseClient) GetConn ¶
func (c *ClickHouseClient) GetConn() driver.Conn
GetConn 获取原生连接(用于高级操作)
func (*ClickHouseClient) GetDB ¶
func (c *ClickHouseClient) GetDB() *sql.DB
GetDB 获取 sql.DB 连接(用于兼容 database/sql 接口)
func (*ClickHouseClient) Insert ¶
func (c *ClickHouseClient) Insert(ctx context.Context, table string, columns []string, rows [][]interface{}) error
Insert 插入数据(自动处理追踪)
func (*ClickHouseClient) Ping ¶
func (c *ClickHouseClient) Ping(ctx context.Context) error
Ping 测试连接
type Config ¶
type Config struct {
Enabled bool `yaml:"enabled" env:"CLICKHOUSE_ENABLED" default:"true"`
Host string `yaml:"host" env:"CLICKHOUSE_HOST" default:"localhost"`
Port int `yaml:"port" env:"CLICKHOUSE_PORT" default:"9000"`
Database string `yaml:"database" env:"CLICKHOUSE_DATABASE" required:"true"`
Username string `yaml:"username" env:"CLICKHOUSE_USERNAME" required:"true"`
Password string `yaml:"password" env:"CLICKHOUSE_PASSWORD" required:"true"`
EnableTLS bool `yaml:"enable_tls" env:"CLICKHOUSE_ENABLE_TLS" default:"false"`
DialTimeout pkgConfig.Duration `yaml:"dial_timeout" env:"CLICKHOUSE_DIAL_TIMEOUT" default:"30s"`
ReadTimeout pkgConfig.Duration `yaml:"read_timeout" env:"CLICKHOUSE_READ_TIMEOUT" default:"30s"`
WriteTimeout pkgConfig.Duration `yaml:"write_timeout" env:"CLICKHOUSE_WRITE_TIMEOUT" default:"30s"`
MaxOpenConns int `yaml:"max_open_conns" env:"CLICKHOUSE_MAX_OPEN_CONNS" default:"100"`
MaxIdleConns int `yaml:"max_idle_conns" env:"CLICKHOUSE_MAX_IDLE_CONNS" default:"10"`
ConnMaxLifetime pkgConfig.Duration `yaml:"conn_max_lifetime" env:"CLICKHOUSE_CONN_MAX_LIFETIME" default:"1h"`
EnableTrace bool `yaml:"enable_trace" env:"CLICKHOUSE_ENABLE_TRACE" default:"true"`
}
Config ClickHouse 配置结构体(用于从配置文件创建)
func (*Config) ConnMaxLifetimeDuration ¶
ConnMaxLifetimeDuration 返回 time.Duration 类型的 ConnMaxLifetime
func (*Config) DialTimeoutDuration ¶
DialTimeoutDuration 返回 time.Duration 类型的 DialTimeout
func (*Config) ReadTimeoutDuration ¶
ReadTimeoutDuration 返回 time.Duration 类型的 ReadTimeout
func (*Config) WriteTimeoutDuration ¶
WriteTimeoutDuration 返回 time.Duration 类型的 WriteTimeout
type Options ¶
type Options struct {
Host string // ClickHouse 主机地址
Port int // ClickHouse 端口
Database string // 数据库名
Username string // 用户名
Password string // 密码
DialTimeout time.Duration // 连接超时
ReadTimeout time.Duration // 读取超时
WriteTimeout time.Duration // 写入超时
MaxOpenConns int // 最大打开连接数
MaxIdleConns int // 最大空闲连接数
ConnMaxLifetime time.Duration // 连接最大生存时间
EnableTLS bool // 是否启用 TLS
EnableTrace bool // 是否启用查询追踪,用于记录查询执行时间
}
Options 结构体定义了 ClickHouse 连接器的配置选项(内部使用)
Click to show internal directories.
Click to hide internal directories.