clickhouse

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: GPL-3.0 Imports: 13 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package clickhouse provides a ClickHouse client implementation

Index

Constants

View Source
const (
	Scheme        = "clickhouse"
	SchemeHTTPS   = "https"
	SchemeHTTP    = "http"
	PortNative    = "9000"
	PortNativeTLS = "9440"
)

Protocol constants for URL parsing.

Variables

View Source
var (
	ErrDestMustBePointerToSlice = errors.New("dest must be a pointer to a slice")
	ErrDestMustBePointer        = errors.New("dest must be a pointer")
	ErrDataMustBeSlice          = errors.New("data must be a slice")
	ErrResponse                 = errors.New("clickhouse error")
	ErrPoolStalled              = errors.New("clickhouse connection pool stalled")
)

Define static errors.

View Source
var ErrInvalidUint64 = errors.New("failed to unmarshal value as uint64")

ErrInvalidUint64 is returned when a value cannot be unmarshaled or scanned as uint64.

View Source
var (
	ErrURLRequired = errors.New("URL is required")
)

Static errors for configuration validation

Functions

func TableExists

func TableExists(ctx context.Context, client ClientInterface, database, table string) (bool, error)

TableExists checks if a table exists in the given database

Types

type AdminConfig added in v0.0.25

type AdminConfig struct {
	Incremental AdminTableConfig `yaml:"incremental"`
	Scheduled   AdminTableConfig `yaml:"scheduled"`
}

AdminConfig contains configurations for different transformation type admin tables

type AdminTableConfig added in v0.0.25

type AdminTableConfig struct {
	Database string `yaml:"database"`
	Table    string `yaml:"table"`
}

AdminTableConfig represents the configuration for a type-specific admin table

type ClientInterface

type ClientInterface interface {
	// QueryOne executes a query and returns a single result
	QueryOne(ctx context.Context, query string, dest any) error
	// QueryMany executes a query and returns multiple results
	QueryMany(ctx context.Context, query string, dest any) error
	// Execute runs a query without returning results (INSERT, ALTER, etc.)
	Execute(ctx context.Context, query string) error
	// BulkInsert performs a bulk insert operation
	BulkInsert(ctx context.Context, table string, data any) error
	// Start initializes the client
	Start() error
	// Stop closes the client
	Stop() error
}

ClientInterface defines the methods for interacting with ClickHouse.

func NewClient

func NewClient(logger *logrus.Logger, cfg *Config) (ClientInterface, error)

NewClient creates a new ClickHouse client using the official Go driver.

type Config

type Config struct {
	// URL supports multiple formats:
	// - Native: clickhouse://user:pass@host:9000
	// - HTTP: http://user:pass@host:8123
	URL string `yaml:"url" validate:"required"`

	Cluster     string `yaml:"cluster"`
	LocalSuffix string `yaml:"localSuffix"`

	QueryTimeout  time.Duration `yaml:"queryTimeout"`
	InsertTimeout time.Duration `yaml:"insertTimeout"`
	Debug         bool          `yaml:"debug"`

	// Connection pool settings
	MaxOpenConns    int           `yaml:"maxOpenConns"`
	MaxIdleConns    int           `yaml:"maxIdleConns"`
	ConnMaxLifetime time.Duration `yaml:"connMaxLifetime"`

	// TLS settings
	InsecureSkipVerify bool `yaml:"insecureSkipVerify"`

	Admin AdminConfig `yaml:"admin"`
}

Config contains ClickHouse connection and cluster settings

func (*Config) SetDefaults

func (c *Config) SetDefaults()

SetDefaults sets default values for the configuration

func (*Config) Validate

func (c *Config) Validate() error

Validate checks if the configuration is valid

type FlexUint64 added in v0.1.7

type FlexUint64 uint64

FlexUint64 is a custom type that can unmarshal from both string and number JSON values and scan from string or numeric database columns.

func (*FlexUint64) Scan added in v0.1.7

func (f *FlexUint64) Scan(src any) error

Scan implements sql.Scanner for FlexUint64 to handle database values. Supports string columns (e.g., '123') and numeric columns.

func (*FlexUint64) UnmarshalJSON added in v0.1.7

func (f *FlexUint64) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler for FlexUint64.

type HealthChecker added in v0.1.7

type HealthChecker interface {
	Healthy() error
}

HealthChecker is implemented by clients that can report whether their connection pool is still able to hand out connections.

Jump to

Keyboard shortcuts

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