clickhouse

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2026 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package clickhouse provides a ClickHouse client implementation

Index

Constants

View Source
const (
	SchemeClickHouse        = "clickhouse"
	SchemeHTTPS             = "https"
	SchemeHTTP              = "http"
	PortClickHouseNative    = "9000"
	PortClickHouseNativeTLS = "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")
	ErrClickHouseResponse       = errors.New("clickhouse error")
)

Define static errors.

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

Jump to

Keyboard shortcuts

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