ClickhouseClient.ts
ClickhouseClient.ts overview
Section titled “ClickhouseClient.ts overview”ClickHouse driver for Effect SQL, backed by @clickhouse/client.
This module provides both the ClickHouse-specific ClickhouseClient
service and the generic Client.SqlClient service. make creates a
scoped client, checks the connection with SELECT 1, maps ClickHouse errors
to SqlError, and aborts in-flight queries when interrupted. The
ClickHouse-specific service adds typed parameters, command execution, insert
queries, query id and settings helpers, a statement compiler, and direct or
config-backed layers.
Since v4.0.0
Exports Grouped by Category
Section titled “Exports Grouped by Category”compiler
Section titled “compiler”makeCompiler
Section titled “makeCompiler”Creates the SQL statement compiler for ClickHouse, emitting typed
{pN: Type} placeholders and escaping identifiers with an optional query
name transform.
Signature
declare const makeCompiler: (transform?: (_: string) => string) => Statement.CompilerSince v4.0.0
constructors
Section titled “constructors”ClickhouseClientConfig (interface)
Section titled “ClickhouseClientConfig (interface)”Configuration for creating a ClickHouse client, combining
@clickhouse/client options with optional span attributes and query/result
name transforms.
Signature
export interface ClickhouseClientConfig extends Clickhouse.ClickHouseClientConfigOptions { readonly spanAttributes?: Record<string, unknown> | undefined readonly transformResultNames?: ((str: string) => string) | undefined readonly transformQueryNames?: ((str: string) => string) | undefined}Since v4.0.0
Creates a scoped ClickhouseClient, verifies connectivity with SELECT 1,
closes the underlying client when the scope ends, maps ClickHouse failures
to SqlError, and aborts plus kills in-flight queries when interrupted.
Signature
declare const make: ( options: ClickhouseClientConfig) => Effect.Effect<ClickhouseClient, SqlError, Scope.Scope | Reactivity.Reactivity>Since v4.0.0
custom types
Section titled “custom types”ClickhouseCustom (type alias)
Section titled “ClickhouseCustom (type alias)”Custom SQL fragment type used for ClickHouse typed parameters created by
ClickhouseClient.param.
Signature
type ClickhouseCustom = ClickhouseParamSince v4.0.0
layers
Section titled “layers”Provides both ClickhouseClient and generic SqlClient services from a
ClickHouse client configuration.
Signature
declare const layer: ( config: ClickhouseClientConfig) => Layer.Layer<ClickhouseClient | Client.SqlClient, Config.ConfigError | SqlError>Since v4.0.0
layerConfig
Section titled “layerConfig”Provides both ClickhouseClient and generic SqlClient services from a
Config-backed ClickHouse client configuration.
Signature
declare const layerConfig: ( config: Config.Wrap<ClickhouseClientConfig>) => Layer.Layer<ClickhouseClient | Client.SqlClient, Config.ConfigError | SqlError>Since v4.0.0
models
Section titled “models”ClickhouseClient (interface)
Section titled “ClickhouseClient (interface)”ClickHouse-specific SqlClient extension with access to its configuration,
typed parameter fragments, command-mode execution, insert queries, and
per-effect query ID and ClickHouse settings.
Signature
export interface ClickhouseClient extends Client.SqlClient { readonly [TypeId]: TypeId readonly config: ClickhouseClientConfig readonly param: (dataType: string, value: unknown) => Statement.Fragment readonly asCommand: <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R> readonly insertQuery: <T = unknown>(options: { readonly table: string readonly values: Clickhouse.InsertValues<Readable, T> readonly format?: Clickhouse.DataFormat }) => Effect.Effect<Clickhouse.InsertResult, SqlError> readonly withQueryId: { (queryId: string): <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R> <A, E, R>(effect: Effect.Effect<A, E, R>, queryId: string): Effect.Effect<A, E, R> } readonly withClickhouseSettings: { ( settings: NonNullable<Clickhouse.BaseQueryParams["clickhouse_settings"]> ): <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R> <A, E, R>( effect: Effect.Effect<A, E, R>, settings: NonNullable<Clickhouse.BaseQueryParams["clickhouse_settings"]> ): Effect.Effect<A, E, R> }}Since v4.0.0
references
Section titled “references”ClickhouseSettings
Section titled “ClickhouseSettings”Fiber reference containing ClickHouse settings to attach to queries, commands, and inserts.
Signature
declare const ClickhouseSettings: Context.Reference< Partial<ClickHouseServerSettings> & Partial<ClickHouseHTTPSettings> & Record<string, string | number | boolean | Clickhouse.SettingsMap | undefined>>Since v4.0.0
ClientMethod
Section titled “ClientMethod”Fiber reference read by the low-level ClickHouse connection to choose query
or command execution for statements; defaults to query.
Signature
declare const ClientMethod: Context.Reference<"query" | "command" | "insert">Since v4.0.0
QueryId
Section titled “QueryId”Fiber reference for the ClickHouse query_id applied to queries and
inserts; a random UUID is generated when no query ID is set.
Signature
declare const QueryId: Context.Reference<string | undefined>Since v4.0.0
services
Section titled “services”ClickhouseClient
Section titled “ClickhouseClient”Service tag for the active ClickHouse SQL client.
When to use
Use to access or provide a ClickHouse SQL client through the Effect context.
Signature
declare const ClickhouseClient: Context.Service<ClickhouseClient, ClickhouseClient>Since v4.0.0
type IDs
Section titled “type IDs”TypeId
Section titled “TypeId”Unique runtime identifier used to tag ClickhouseClient values.
Signature
declare const TypeId: "~@effect/sql-clickhouse/ClickhouseClient"Since v4.0.0
TypeId (type alias)
Section titled “TypeId (type alias)”Type-level literal for the ClickhouseClient runtime identifier.
Signature
type TypeId = "~@effect/sql-clickhouse/ClickhouseClient"Since v4.0.0