Documentation
¶
Overview ¶
Package chx is a thin ClickHouse client for analytics / long-term stores.
The write path uses the native clickhouse-go/v2 connection (driver.Conn), which speaks the columnar native protocol and supports PrepareBatch for large bulk inserts. Schema is applied via skit/migrate (goose, ClickHouse dialect) from a caller-supplied migrations fs.FS over a separate database/sql handle, because goose needs database/sql rather than the native conn.
ClickHouse suits analytics / long-term storage: finished, structured data in large batches, never on a hot ingest path. This client is an optional building block — importing it is what pulls in the clickhouse-go/v2 dependency; wire it in only when a ClickHouse endpoint is configured.
Index ¶
- func Migrate(ctx context.Context, cfg Config, fsys fs.FS) error
- type Client
- func (c *Client) Close() error
- func (c *Client) Conn() driver.Conn
- func (c *Client) Exec(ctx context.Context, query string, args ...any) error
- func (c *Client) Name() string
- func (c *Client) Ping(ctx context.Context) error
- func (c *Client) PrepareBatch(ctx context.Context, query string) (driver.Batch, error)
- func (c *Client) Query(ctx context.Context, query string, args ...any) (driver.Rows, error)
- func (c *Client) Select(ctx context.Context, dest any, query string, args ...any) error
- type Config
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Migrate ¶
Migrate applies the pending DDL migrations in fsys (goose SQL files, rooted at the directory that holds them) using goose's ClickHouse dialect over a dedicated database/sql handle. It is idempotent. The caller supplies its own migrations FS, e.g. fs.Sub(embedded, "migrations"). goose needs a database/sql connection (clickhouse.OpenDB), separate from the native conn.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a ClickHouse connection. It wraps the native driver.Conn; use Conn for direct access or the thin pass-throughs below.
func Open ¶
Open dials ClickHouse and verifies connectivity with a ping. It does NOT apply migrations — call Migrate explicitly (usually once at startup) so schema changes stay an intentional operational step, not a side effect of connecting.
func (*Client) Conn ¶
Conn returns the underlying native connection for direct use (e.g. PrepareBatch with column-level control, or Select into structs).
func (*Client) PrepareBatch ¶
PrepareBatch opens a client-side batch for a bulk INSERT — the primary write path (CH loves large batches).
type Config ¶
type Config struct {
Addrs []string
Database string
Username string
Password string
DialTimeout time.Duration
MaxOpenConns int
Compression bool
}
Config describes how to reach ClickHouse. Addrs is a list of host:port native endpoints (default native port 9000). Compression enables LZ4 wire compression, worthwhile for the large batches CH ingests.