@effect/sql-clickhouse 4.0.0-beta.7 → 4.0.0-beta.70

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,30 +1,58 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * ClickHouse client implementation for Effect SQL, backed by
3
+ * `@clickhouse/client`.
4
+ *
5
+ * This module exposes constructors and layers for providing both the
6
+ * ClickHouse-specific `ClickhouseClient` service and the generic `SqlClient`
7
+ * service. It is intended for analytical application queries, migrations,
8
+ * background jobs, bulk inserts, and streaming reads that need Effect SQL query
9
+ * compilation, scoped lifecycle management, interruption, and consistent
10
+ * `SqlError` classification for ClickHouse failures.
11
+ *
12
+ * The client uses the ClickHouse HTTP client APIs for `query`, `command`, and
13
+ * `insert` operations. Regular queries read JSON result sets, `executeValues`
14
+ * requests `JSONCompact`, streams request `JSONEachRow`, and `insertQuery`
15
+ * defaults inserts to `JSONEachRow`. Interrupting an operation aborts the
16
+ * underlying HTTP request and attempts to kill the generated or supplied
17
+ * `query_id`. The statement compiler emits ClickHouse typed placeholders such
18
+ * as `{p1: Type}`; use `param` when the inferred type is too broad, and write
19
+ * ClickHouse-specific clauses such as engines, `SETTINGS`, `FORMAT`, or
20
+ * cluster directives explicitly.
21
+ *
22
+ * @since 4.0.0
3
23
  */
4
24
  import * as Clickhouse from "@clickhouse/client";
5
25
  import * as Config from "effect/Config";
26
+ import * as Context from "effect/Context";
6
27
  import * as Effect from "effect/Effect";
7
28
  import * as Layer from "effect/Layer";
8
29
  import type * as Scope from "effect/Scope";
9
- import * as ServiceMap from "effect/ServiceMap";
10
30
  import * as Reactivity from "effect/unstable/reactivity/Reactivity";
11
31
  import * as Client from "effect/unstable/sql/SqlClient";
12
32
  import { SqlError } from "effect/unstable/sql/SqlError";
13
33
  import * as Statement from "effect/unstable/sql/Statement";
14
34
  import type { Readable } from "node:stream";
15
35
  /**
16
- * @category type ids
17
- * @since 1.0.0
36
+ * Unique runtime identifier used to tag `ClickhouseClient` values.
37
+ *
38
+ * @category type IDs
39
+ * @since 4.0.0
18
40
  */
19
41
  export declare const TypeId: TypeId;
20
42
  /**
21
- * @category type ids
22
- * @since 1.0.0
43
+ * Type-level literal for the `ClickhouseClient` runtime identifier.
44
+ *
45
+ * @category type IDs
46
+ * @since 4.0.0
23
47
  */
24
48
  export type TypeId = "~@effect/sql-clickhouse/ClickhouseClient";
25
49
  /**
50
+ * ClickHouse-specific `SqlClient` extension with access to its configuration,
51
+ * typed parameter fragments, command-mode execution, insert queries, and
52
+ * per-effect query ID and ClickHouse settings.
53
+ *
26
54
  * @category models
27
- * @since 1.0.0
55
+ * @since 4.0.0
28
56
  */
29
57
  export interface ClickhouseClient extends Client.SqlClient {
30
58
  readonly [TypeId]: TypeId;
@@ -46,13 +74,19 @@ export interface ClickhouseClient extends Client.SqlClient {
46
74
  };
47
75
  }
48
76
  /**
77
+ * Context service tag for accessing the active `ClickhouseClient`.
78
+ *
49
79
  * @category tags
50
- * @since 1.0.0
80
+ * @since 4.0.0
51
81
  */
52
- export declare const ClickhouseClient: ServiceMap.Service<ClickhouseClient, ClickhouseClient>;
82
+ export declare const ClickhouseClient: Context.Service<ClickhouseClient, ClickhouseClient>;
53
83
  /**
84
+ * Configuration for creating a ClickHouse client, combining
85
+ * `@clickhouse/client` options with optional span attributes and query/result
86
+ * name transforms.
87
+ *
54
88
  * @category constructors
55
- * @since 1.0.0
89
+ * @since 4.0.0
56
90
  */
57
91
  export interface ClickhouseClientConfig extends Clickhouse.ClickHouseClientConfigOptions {
58
92
  readonly spanAttributes?: Record<string, unknown> | undefined;
@@ -60,48 +94,74 @@ export interface ClickhouseClientConfig extends Clickhouse.ClickHouseClientConfi
60
94
  readonly transformQueryNames?: ((str: string) => string) | undefined;
61
95
  }
62
96
  /**
97
+ * Creates a scoped `ClickhouseClient`, verifies connectivity with `SELECT 1`,
98
+ * closes the underlying client when the scope ends, maps ClickHouse failures
99
+ * to `SqlError`, and aborts plus kills in-flight queries when interrupted.
100
+ *
63
101
  * @category constructors
64
- * @since 1.0.0
102
+ * @since 4.0.0
65
103
  */
66
104
  export declare const make: (options: ClickhouseClientConfig) => Effect.Effect<ClickhouseClient, SqlError, Scope.Scope | Reactivity.Reactivity>;
67
105
  /**
68
- * @category References
69
- * @since 1.0.0
106
+ * Fiber reference read by the low-level ClickHouse connection to choose query
107
+ * or command execution for statements; defaults to `query`.
108
+ *
109
+ * @category references
110
+ * @since 4.0.0
70
111
  */
71
- export declare const ClientMethod: ServiceMap.Reference<"query" | "command" | "insert">;
112
+ export declare const ClientMethod: Context.Reference<"query" | "command" | "insert">;
72
113
  /**
73
- * @category References
74
- * @since 1.0.0
114
+ * Fiber reference for the ClickHouse `query_id` applied to queries and
115
+ * inserts; a random UUID is generated when no query ID is set.
116
+ *
117
+ * @category references
118
+ * @since 4.0.0
75
119
  */
76
- export declare const QueryId: ServiceMap.Reference<string | undefined>;
120
+ export declare const QueryId: Context.Reference<string | undefined>;
77
121
  /**
78
- * @category References
79
- * @since 1.0.0
122
+ * Fiber reference containing ClickHouse settings to attach to queries,
123
+ * commands, and inserts.
124
+ *
125
+ * @category references
126
+ * @since 4.0.0
80
127
  */
81
- export declare const ClickhouseSettings: ServiceMap.Reference<NonNullable<Clickhouse.BaseQueryParams["clickhouse_settings"]>>;
128
+ export declare const ClickhouseSettings: Context.Reference<NonNullable<Clickhouse.BaseQueryParams["clickhouse_settings"]>>;
82
129
  /**
130
+ * Provides both `ClickhouseClient` and generic `SqlClient` services from a
131
+ * `Config`-backed ClickHouse client configuration.
132
+ *
83
133
  * @category layers
84
- * @since 1.0.0
134
+ * @since 4.0.0
85
135
  */
86
136
  export declare const layerConfig: (config: Config.Wrap<ClickhouseClientConfig>) => Layer.Layer<ClickhouseClient | Client.SqlClient, Config.ConfigError | SqlError>;
87
137
  /**
138
+ * Provides both `ClickhouseClient` and generic `SqlClient` services from a
139
+ * ClickHouse client configuration.
140
+ *
88
141
  * @category layers
89
- * @since 1.0.0
142
+ * @since 4.0.0
90
143
  */
91
144
  export declare const layer: (config: ClickhouseClientConfig) => Layer.Layer<ClickhouseClient | Client.SqlClient, Config.ConfigError | SqlError>;
92
145
  /**
146
+ * Creates the SQL statement compiler for ClickHouse, emitting typed
147
+ * `{pN: Type}` placeholders and escaping identifiers with an optional query
148
+ * name transform.
149
+ *
93
150
  * @category compiler
94
- * @since 1.0.0
151
+ * @since 4.0.0
95
152
  */
96
153
  export declare const makeCompiler: (transform?: (_: string) => string) => Statement.Compiler;
97
154
  /**
155
+ * Custom SQL fragment type used for ClickHouse typed parameters created by
156
+ * `ClickhouseClient.param`.
157
+ *
98
158
  * @category custom types
99
- * @since 1.0.0
159
+ * @since 4.0.0
100
160
  */
101
161
  export type ClickhouseCustom = ClickhouseParam;
102
162
  /**
103
163
  * @category custom types
104
- * @since 1.0.0
164
+ * @since 4.0.0
105
165
  */
106
166
  interface ClickhouseParam extends Statement.Custom<"ClickhouseParam", string, unknown> {
107
167
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ClickhouseClient.d.ts","sourceRoot":"","sources":["../src/ClickhouseClient.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,UAAU,MAAM,oBAAoB,CAAA;AAEhD,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAGvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAA;AAC1C,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAA;AAE/C,OAAO,KAAK,UAAU,MAAM,uCAAuC,CAAA;AACnE,OAAO,KAAK,MAAM,MAAM,+BAA+B,CAAA;AAEvD,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAA;AACvD,OAAO,KAAK,SAAS,MAAM,+BAA+B,CAAA;AAE1D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAK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AAgB,GAAG,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,WAAW,GAAG,QAAQ,CAMxC,CAAA;AA2BzC;;;;;;;GAOG;AACH,eAAO,MAAM,YAAY,GAAI,YAAY,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,uBAiB1D,CAAA;AAMJ;;;;;;GAMG;AACH,MAAM,MAAM,gBAAgB,GAAG,eAAe,CAAA;AAE9C;;;GAGG;AACH,UAAU,eAAgB,SAAQ,SAAS,CAAC,MAAM,CAAC,iBAAiB,EAAE,MAAM,EAAE,OAAO,CAAC;CAAG"}
@@ -1,36 +1,102 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * ClickHouse client implementation for Effect SQL, backed by
3
+ * `@clickhouse/client`.
4
+ *
5
+ * This module exposes constructors and layers for providing both the
6
+ * ClickHouse-specific `ClickhouseClient` service and the generic `SqlClient`
7
+ * service. It is intended for analytical application queries, migrations,
8
+ * background jobs, bulk inserts, and streaming reads that need Effect SQL query
9
+ * compilation, scoped lifecycle management, interruption, and consistent
10
+ * `SqlError` classification for ClickHouse failures.
11
+ *
12
+ * The client uses the ClickHouse HTTP client APIs for `query`, `command`, and
13
+ * `insert` operations. Regular queries read JSON result sets, `executeValues`
14
+ * requests `JSONCompact`, streams request `JSONEachRow`, and `insertQuery`
15
+ * defaults inserts to `JSONEachRow`. Interrupting an operation aborts the
16
+ * underlying HTTP request and attempts to kill the generated or supplied
17
+ * `query_id`. The statement compiler emits ClickHouse typed placeholders such
18
+ * as `{p1: Type}`; use `param` when the inferred type is too broad, and write
19
+ * ClickHouse-specific clauses such as engines, `SETTINGS`, `FORMAT`, or
20
+ * cluster directives explicitly.
21
+ *
22
+ * @since 4.0.0
3
23
  */
4
24
  import * as Clickhouse from "@clickhouse/client";
5
25
  import * as NodeStream from "@effect/platform-node/NodeStream";
6
26
  import * as Config from "effect/Config";
27
+ import * as Context from "effect/Context";
7
28
  import * as Duration from "effect/Duration";
8
29
  import * as Effect from "effect/Effect";
9
30
  import * as Fiber from "effect/Fiber";
10
31
  import { dual } from "effect/Function";
11
32
  import * as Layer from "effect/Layer";
12
- import * as ServiceMap from "effect/ServiceMap";
13
33
  import * as Stream from "effect/Stream";
14
34
  import * as Reactivity from "effect/unstable/reactivity/Reactivity";
15
35
  import * as Client from "effect/unstable/sql/SqlClient";
16
- import { SqlError } from "effect/unstable/sql/SqlError";
36
+ import { AuthenticationError, AuthorizationError, ConnectionError, SqlError, SqlSyntaxError, StatementTimeoutError, UnknownError } from "effect/unstable/sql/SqlError";
17
37
  import * as Statement from "effect/unstable/sql/Statement";
18
38
  import * as Crypto from "node:crypto";
19
39
  const ATTR_DB_SYSTEM_NAME = "db.system.name";
20
40
  const ATTR_DB_NAMESPACE = "db.namespace";
41
+ const clickhouseCodeFromCause = cause => {
42
+ if (typeof cause !== "object" || cause === null || !("code" in cause)) {
43
+ return undefined;
44
+ }
45
+ const code = cause.code;
46
+ if (typeof code === "number") {
47
+ return code;
48
+ }
49
+ if (typeof code === "string") {
50
+ const parsed = Number(code);
51
+ return Number.isNaN(parsed) ? undefined : parsed;
52
+ }
53
+ return undefined;
54
+ };
55
+ const clickhouseSyntaxErrorCodes = /*#__PURE__*/new Set([36, 60, 62, 242]);
56
+ const classifyError = (cause, message, operation, fallback = "unknown") => {
57
+ const props = {
58
+ cause,
59
+ message,
60
+ operation
61
+ };
62
+ const code = clickhouseCodeFromCause(cause);
63
+ if (code !== undefined) {
64
+ if (code === 516) {
65
+ return new AuthenticationError(props);
66
+ }
67
+ if (code === 497) {
68
+ return new AuthorizationError(props);
69
+ }
70
+ if (clickhouseSyntaxErrorCodes.has(code)) {
71
+ return new SqlSyntaxError(props);
72
+ }
73
+ if (code === 159 || code === 469) {
74
+ return new StatementTimeoutError(props);
75
+ }
76
+ }
77
+ return fallback === "connection" ? new ConnectionError(props) : new UnknownError(props);
78
+ };
21
79
  /**
22
- * @category type ids
23
- * @since 1.0.0
80
+ * Unique runtime identifier used to tag `ClickhouseClient` values.
81
+ *
82
+ * @category type IDs
83
+ * @since 4.0.0
24
84
  */
25
85
  export const TypeId = "~@effect/sql-clickhouse/ClickhouseClient";
26
86
  /**
87
+ * Context service tag for accessing the active `ClickhouseClient`.
88
+ *
27
89
  * @category tags
28
- * @since 1.0.0
90
+ * @since 4.0.0
29
91
  */
30
- export const ClickhouseClient = /*#__PURE__*/ServiceMap.Service("@effect/sql-clickhouse/ClickhouseClient");
92
+ export const ClickhouseClient = /*#__PURE__*/Context.Service("@effect/sql-clickhouse/ClickhouseClient");
31
93
  /**
94
+ * Creates a scoped `ClickhouseClient`, verifies connectivity with `SELECT 1`,
95
+ * closes the underlying client when the scope ends, maps ClickHouse failures
96
+ * to `SqlError`, and aborts plus kills in-flight queries when interrupted.
97
+ *
32
98
  * @category constructors
33
- * @since 1.0.0
99
+ * @since 4.0.0
34
100
  */
35
101
  export const make = options => Effect.gen(function* () {
36
102
  const compiler = makeCompiler(options.transformQueryNames);
@@ -41,14 +107,16 @@ export const make = options => Effect.gen(function* () {
41
107
  query: "SELECT 1"
42
108
  }),
43
109
  catch: cause => new SqlError({
44
- cause,
45
- message: "ClickhouseClient: Failed to connect"
110
+ reason: classifyError(cause, "ClickhouseClient: Failed to connect", "connect", "connection")
46
111
  })
47
112
  }), () => Effect.promise(() => client.close())).pipe(Effect.timeoutOrElse({
48
113
  duration: Duration.seconds(5),
49
- onTimeout: () => Effect.fail(new SqlError({
50
- message: "ClickhouseClient: Connection timeout",
51
- cause: new Error("connection timeout")
114
+ orElse: () => Effect.fail(new SqlError({
115
+ reason: new ConnectionError({
116
+ message: "ClickhouseClient: Connection timeout",
117
+ cause: new Error("connection timeout"),
118
+ operation: "connect"
119
+ })
52
120
  }))
53
121
  }));
54
122
  class ConnectionImpl {
@@ -75,8 +143,7 @@ export const make = options => Effect.gen(function* () {
75
143
  query_id: queryId,
76
144
  clickhouse_settings: settings
77
145
  }).then(result => resume(Effect.succeed(result)), cause => resume(Effect.fail(new SqlError({
78
- cause,
79
- message: "Failed to execute statement"
146
+ reason: classifyError(cause, "Failed to execute statement", "execute")
80
147
  }))));
81
148
  } else {
82
149
  this.conn.query({
@@ -87,8 +154,7 @@ export const make = options => Effect.gen(function* () {
87
154
  clickhouse_settings: settings,
88
155
  format
89
156
  }).then(result => resume(Effect.succeed(result)), cause => resume(Effect.fail(new SqlError({
90
- cause,
91
- message: "Failed to execute statement"
157
+ reason: classifyError(cause, "Failed to execute statement", "execute")
92
158
  }))));
93
159
  }
94
160
  return Effect.suspend(() => {
@@ -128,8 +194,7 @@ export const make = options => Effect.gen(function* () {
128
194
  return NodeStream.fromReadable({
129
195
  evaluate: () => result.stream(),
130
196
  onError: cause => new SqlError({
131
- cause,
132
- message: "Failed to execute stream"
197
+ reason: classifyError(cause, "Failed to execute stream", "stream")
133
198
  })
134
199
  });
135
200
  }), Stream.unwrap, Stream.chunks, Stream.mapEffect(chunk => {
@@ -142,8 +207,7 @@ export const make = options => Effect.gen(function* () {
142
207
  return Effect.tryPromise({
143
208
  try: () => Promise.all(promises).then(rows => transformRows ? transformRows(rows) : rows),
144
209
  catch: cause => new SqlError({
145
- cause,
146
- message: "Failed to parse row"
210
+ reason: classifyError(cause, "Failed to parse row", "parseRow")
147
211
  })
148
212
  });
149
213
  }), Stream.flattenIterable);
@@ -178,8 +242,7 @@ export const make = options => Effect.gen(function* () {
178
242
  query_id: queryId,
179
243
  clickhouse_settings: settings
180
244
  }).then(result => resume(Effect.succeed(result)), cause => resume(Effect.fail(new SqlError({
181
- cause,
182
- message: "Failed to insert data"
245
+ reason: classifyError(cause, "Failed to insert data", "insert")
183
246
  }))));
184
247
  return Effect.suspend(() => {
185
248
  controller.abort();
@@ -194,36 +257,51 @@ export const make = options => Effect.gen(function* () {
194
257
  });
195
258
  });
196
259
  /**
197
- * @category References
198
- * @since 1.0.0
260
+ * Fiber reference read by the low-level ClickHouse connection to choose query
261
+ * or command execution for statements; defaults to `query`.
262
+ *
263
+ * @category references
264
+ * @since 4.0.0
199
265
  */
200
- export const ClientMethod = /*#__PURE__*/ServiceMap.Reference("@effect/sql-clickhouse/ClickhouseClient/ClientMethod", {
266
+ export const ClientMethod = /*#__PURE__*/Context.Reference("@effect/sql-clickhouse/ClickhouseClient/ClientMethod", {
201
267
  defaultValue: () => "query"
202
268
  });
203
269
  /**
204
- * @category References
205
- * @since 1.0.0
270
+ * Fiber reference for the ClickHouse `query_id` applied to queries and
271
+ * inserts; a random UUID is generated when no query ID is set.
272
+ *
273
+ * @category references
274
+ * @since 4.0.0
206
275
  */
207
- export const QueryId = /*#__PURE__*/ServiceMap.Reference("@effect/sql-clickhouse/ClickhouseClient/QueryId", {
276
+ export const QueryId = /*#__PURE__*/Context.Reference("@effect/sql-clickhouse/ClickhouseClient/QueryId", {
208
277
  defaultValue: () => undefined
209
278
  });
210
279
  /**
211
- * @category References
212
- * @since 1.0.0
280
+ * Fiber reference containing ClickHouse settings to attach to queries,
281
+ * commands, and inserts.
282
+ *
283
+ * @category references
284
+ * @since 4.0.0
213
285
  */
214
- export const ClickhouseSettings = /*#__PURE__*/ServiceMap.Reference("@effect/sql-clickhouse/ClickhouseClient/ClickhouseSettings", {
286
+ export const ClickhouseSettings = /*#__PURE__*/Context.Reference("@effect/sql-clickhouse/ClickhouseClient/ClickhouseSettings", {
215
287
  defaultValue: () => ({})
216
288
  });
217
289
  /**
290
+ * Provides both `ClickhouseClient` and generic `SqlClient` services from a
291
+ * `Config`-backed ClickHouse client configuration.
292
+ *
218
293
  * @category layers
219
- * @since 1.0.0
294
+ * @since 4.0.0
220
295
  */
221
- export const layerConfig = config => Layer.effectServices(Config.unwrap(config).asEffect().pipe(Effect.flatMap(make), Effect.map(client => ServiceMap.make(ClickhouseClient, client).pipe(ServiceMap.add(Client.SqlClient, client))))).pipe(Layer.provide(Reactivity.layer));
296
+ export const layerConfig = config => Layer.effectContext(Config.unwrap(config).pipe(Effect.flatMap(make), Effect.map(client => Context.make(ClickhouseClient, client).pipe(Context.add(Client.SqlClient, client))))).pipe(Layer.provide(Reactivity.layer));
222
297
  /**
298
+ * Provides both `ClickhouseClient` and generic `SqlClient` services from a
299
+ * ClickHouse client configuration.
300
+ *
223
301
  * @category layers
224
- * @since 1.0.0
302
+ * @since 4.0.0
225
303
  */
226
- export const layer = config => Layer.effectServices(Effect.map(make(config), client => ServiceMap.make(ClickhouseClient, client).pipe(ServiceMap.add(Client.SqlClient, client)))).pipe(Layer.provide(Reactivity.layer));
304
+ export const layer = config => Layer.effectContext(Effect.map(make(config), client => Context.make(ClickhouseClient, client).pipe(Context.add(Client.SqlClient, client)))).pipe(Layer.provide(Reactivity.layer));
227
305
  const typeFromUnknown = value => {
228
306
  if (Statement.isFragment(value)) {
229
307
  return typeFromUnknown(value.segments[0]);
@@ -249,8 +327,12 @@ const typeFromUnknown = value => {
249
327
  }
250
328
  };
251
329
  /**
330
+ * Creates the SQL statement compiler for ClickHouse, emitting typed
331
+ * `{pN: Type}` placeholders and escaping identifiers with an optional query
332
+ * name transform.
333
+ *
252
334
  * @category compiler
253
- * @since 1.0.0
335
+ * @since 4.0.0
254
336
  */
255
337
  export const makeCompiler = transform => Statement.makeCompiler({
256
338
  dialect: "sqlite",
@@ -1 +1 @@
1
- {"version":3,"file":"ClickhouseClient.js","names":["Clickhouse","NodeStream","Config","Duration","Effect","Fiber","dual","Layer","ServiceMap","Stream","Reactivity","Client","SqlError","Statement","Crypto","ATTR_DB_SYSTEM_NAME","ATTR_DB_NAMESPACE","TypeId","ClickhouseClient","Service","make","options","gen","compiler","makeCompiler","transformQueryNames","transformRows","transformResultNames","defaultTransforms","array","undefined","client","createClient","acquireRelease","tryPromise","try","exec","query","catch","cause","message","promise","close","pipe","timeoutOrElse","duration","seconds","onTimeout","fail","Error","ConnectionImpl","conn","constructor","runRaw","sql","params","format","paramsObj","i","length","withFiber","fiber","method","getRef","ClientMethod","callback","resume","queryId","QueryId","randomUUID","settings","ClickhouseSettings","controller","AbortController","command","query_params","abort_signal","signal","query_id","clickhouse_settings","then","result","succeed","suspend","abort","run","flatMap","json","data","execute","map","executeRaw","executeValues","executeUnprepared","executeStream","empty","fromReadable","evaluate","stream","onError","unwrap","chunks","mapEffect","chunk","promises","rows","row","push","Promise","all","flattenIterable","connection","Object","assign","acquirer","spanAttributes","entries","database","beginTransaction","config","param","dataType","value","fragment","clickhouseParam","asCommand","effect","provideService","insertQuery","getCurrent","insert","withQueryId","withClickhouseSettings","Reference","defaultValue","layerConfig","effectServices","asEffect","add","SqlClient","provide","layer","typeFromUnknown","isFragment","segments","isClickhouseParam","paramA","Array","isArray","Date","transform","dialect","placeholder","u","onIdentifier","withoutTransform","escape","onRecordUpdate","onCustom","type","paramB","defaultEscape","custom","isCustom"],"sources":["../src/ClickhouseClient.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAGA,OAAO,KAAKA,UAAU,MAAM,oBAAoB;AAChD,OAAO,KAAKC,UAAU,MAAM,kCAAkC;AAC9D,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,QAAQ,MAAM,iBAAiB;AAC3C,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,KAAK,MAAM,cAAc;AACrC,SAASC,IAAI,QAAQ,iBAAiB;AACtC,OAAO,KAAKC,KAAK,MAAM,cAAc;AAErC,OAAO,KAAKC,UAAU,MAAM,mBAAmB;AAC/C,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,UAAU,MAAM,uCAAuC;AACnE,OAAO,KAAKC,MAAM,MAAM,+BAA+B;AAEvD,SAASC,QAAQ,QAAQ,8BAA8B;AACvD,OAAO,KAAKC,SAAS,MAAM,+BAA+B;AAC1D,OAAO,KAAKC,MAAM,MAAM,aAAa;AAGrC,MAAMC,mBAAmB,GAAG,gBAAgB;AAC5C,MAAMC,iBAAiB,GAAG,cAAc;AAExC;;;;AAIA,OAAO,MAAMC,MAAM,GAAW,0CAA0C;AAqCxE;;;;AAIA,OAAO,MAAMC,gBAAgB,gBAAGV,UAAU,CAACW,OAAO,C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,SAAS,GACrB,UAAS5B,KAAK,EAAEiC,gBAAgB;IAC9B,OAAOA,gBAAgB,GAAGC,MAAM,CAAClC,KAAK,CAAC,GAAGkC,MAAM,CAACN,SAAS,CAAC5B,KAAK,CAAC,CAAC;EACpE,CAAC,GACDkC,MAAM;EACRC,cAAcA,CAAA;IACZ,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC;EACjB,CAAC;EACDC,QAAQA,CAACC,IAAI,EAAEP,WAAW;IACxB,OAAO,CAACA,WAAW,CAACO,IAAI,CAAC,EAAE,CAACA,IAAI,CAACC,MAAM,CAAC,CAAC;EAC3C;CACD,CAAC;AAEJ;AAEA,MAAMJ,MAAM,gBAAG/I,SAAS,CAACoJ,aAAa,CAAC,IAAI,CAAC;AAc5C,MAAMrC,eAAe,gBAAG/G,SAAS,CAACqJ,MAAM,CAAkB,iBAAiB,CAAC;AAC5E,MAAMjB,iBAAiB,gBAAGpI,SAAS,CAACsJ,QAAQ,CAAkB,iBAAiB,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"ClickhouseClient.js","names":["Clickhouse","NodeStream","Config","Context","Duration","Effect","Fiber","dual","Layer","Stream","Reactivity","Client","AuthenticationError","AuthorizationError","ConnectionError","SqlError","SqlSyntaxError","StatementTimeoutError","UnknownError","Statement","Crypto","ATTR_DB_SYSTEM_NAME","ATTR_DB_NAMESPACE","clickhouseCodeFromCause","cause","undefined","code","parsed","Number","isNaN","clickhouseSyntaxErrorCodes","Set","classifyError","message","operation","fallback","props","has","TypeId","ClickhouseClient","Service","make","options","gen","compiler","makeCompiler","transformQueryNames","transformRows","transformResultNames","defaultTransforms","array","client","createClient","acquireRelease","tryPromise","try","exec","query","catch","reason","promise","close","pipe","timeoutOrElse","duration","seconds","orElse","fail","Error","ConnectionImpl","conn","constructor","runRaw","sql","params","format","paramsObj","i","length","withFiber","fiber","method","getRef","ClientMethod","callback","resume","queryId","QueryId","randomUUID","settings","ClickhouseSettings","controller","AbortController","command","query_params","abort_signal","signal","query_id","clickhouse_settings","then","result","succeed","suspend","abort","run","flatMap","json","data","execute","map","executeRaw","executeValues","executeUnprepared","executeStream","empty","fromReadable","evaluate","stream","onError","unwrap","chunks","mapEffect","chunk","promises","rows","row","push","Promise","all","flattenIterable","connection","Object","assign","acquirer","spanAttributes","entries","database","beginTransaction","config","param","dataType","value","fragment","clickhouseParam","asCommand","effect","provideService","insertQuery","getCurrent","insert","withQueryId","withClickhouseSettings","Reference","defaultValue","layerConfig","effectContext","add","SqlClient","provide","layer","typeFromUnknown","isFragment","segments","isClickhouseParam","paramA","Array","isArray","Date","transform","dialect","placeholder","u","onIdentifier","withoutTransform","escape","onRecordUpdate","onCustom","type","paramB","defaultEscape","custom","isCustom"],"sources":["../src/ClickhouseClient.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;AAuBA,OAAO,KAAKA,UAAU,MAAM,oBAAoB;AAChD,OAAO,KAAKC,UAAU,MAAM,kCAAkC;AAC9D,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,OAAO,MAAM,gBAAgB;AACzC,OAAO,KAAKC,QAAQ,MAAM,iBAAiB;AAC3C,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,KAAK,MAAM,cAAc;AACrC,SAASC,IAAI,QAAQ,iBAAiB;AACtC,OAAO,KAAKC,KAAK,MAAM,cAAc;AAErC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,UAAU,MAAM,uCAAuC;AACnE,OAAO,KAAKC,MAAM,MAAM,+BAA+B;AAEvD,SACEC,mBAAmB,EACnBC,kBAAkB,EAClBC,eAAe,EACfC,QAAQ,EACRC,cAAc,EACdC,qBAAqB,EACrBC,YAAY,QACP,8BAA8B;AACrC,OAAO,KAAKC,SAAS,MAAM,+BAA+B;AAC1D,OAAO,KAAKC,MAAM,MAAM,aAAa;AAGrC,MAAMC,mBAAmB,GAAG,gBAAgB;AAC5C,MAAMC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1,5 +1,22 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * Utilities for applying Effect SQL migrations to ClickHouse databases.
3
+ *
4
+ * This module re-exports the shared `Migrator` loaders and error types, then
5
+ * provides `run` and `layer` helpers for applying ordered migrations through
6
+ * the current ClickHouse `SqlClient`. It is typically used during application
7
+ * startup, deployment, or integration tests that need to prepare analytical
8
+ * tables before dependent services begin reading or writing data.
9
+ *
10
+ * Applied migrations are stored in `effect_sql_migrations` by default and use
11
+ * the shared `<id>_<name>` loader convention. Only migrations with ids greater
12
+ * than the latest recorded id are run. ClickHouse schema changes often depend
13
+ * on engine, `ORDER BY`, database, and cluster settings, and many deployments
14
+ * rely on explicit `ON CLUSTER` clauses or coordinated rollout tooling. This
15
+ * adapter does not add a ClickHouse-specific table lock or schema dumper, so
16
+ * coordinate concurrent migrators and do not expect `schemaDirectory` to emit a
17
+ * ClickHouse schema snapshot.
18
+ *
19
+ * @since 4.0.0
3
20
  */
4
21
  import type * as Effect from "effect/Effect";
5
22
  import * as Layer from "effect/Layer";
@@ -7,17 +24,23 @@ import * as Migrator from "effect/unstable/sql/Migrator";
7
24
  import type * as Client from "effect/unstable/sql/SqlClient";
8
25
  import type { SqlError } from "effect/unstable/sql/SqlError";
9
26
  /**
10
- * @since 1.0.0
27
+ * @since 4.0.0
11
28
  */
12
29
  export * from "effect/unstable/sql/Migrator";
13
30
  /**
14
- * @category constructor
15
- * @since 1.0.0
31
+ * Runs SQL migrations for ClickHouse using the supplied migrator options and
32
+ * returns the applied migration IDs and names.
33
+ *
34
+ * @category constructors
35
+ * @since 4.0.0
16
36
  */
17
37
  export declare const run: <R2 = never>({ loader, schemaDirectory, table }: Migrator.MigratorOptions<R2>) => Effect.Effect<ReadonlyArray<readonly [id: number, name: string]>, Migrator.MigrationError | SqlError, Client.SqlClient | R2>;
18
38
  /**
39
+ * Creates a layer that runs the configured ClickHouse migrations during layer
40
+ * construction and provides no services.
41
+ *
19
42
  * @category layers
20
- * @since 1.0.0
43
+ * @since 4.0.0
21
44
  */
22
45
  export declare const layer: <R>(options: Migrator.MigratorOptions<R>) => Layer.Layer<never, Migrator.MigrationError | SqlError, Client.SqlClient | R>;
23
46
  //# sourceMappingURL=ClickhouseMigrator.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ClickhouseMigrator.d.ts","sourceRoot":"","sources":["../src/ClickhouseMigrator.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAA;AAC5C,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,QAAQ,MAAM,8BAA8B,CAAA;AACxD,OAAO,KAAK,KAAK,MAAM,MAAM,+BAA+B,CAAA;AAC5D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAA;AAE5D;;GAEG;AACH,cAAc,8BAA8B,CAAA;AAE5C;;;GAGG;AACH,eAAO,MAAM,GAAG,EAAE,CAAC,EAAE,GAAG,KAAK,EAC3B,EAAE,MAAM,EAAE,eAAe,EAAE,KAAK,EAAE,EAAE,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC,KAC7D,MAAM,CAAC,MAAM,CAChB,aAAa,CAAC,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,EAClD,QAAQ,CAAC,cAAc,GAAG,QAAQ,EAClC,MAAM,CAAC,SAAS,GAAG,EAAE,CACF,CAAA;AAErB;;;GAGG;AACH,eAAO,MAAM,KAAK,GAAI,CAAC,EACrB,SAAS,QAAQ,CAAC,eAAe,CAAC,CAAC,CAAC,KACnC,KAAK,CAAC,KAAK,CACZ,KAAK,EACL,QAAQ,CAAC,cAAc,GAAG,QAAQ,EAClC,MAAM,CAAC,SAAS,GAAG,CAAC,CACgB,CAAA"}
1
+ {"version":3,"file":"ClickhouseMigrator.d.ts","sourceRoot":"","sources":["../src/ClickhouseMigrator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAA;AAC5C,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,QAAQ,MAAM,8BAA8B,CAAA;AACxD,OAAO,KAAK,KAAK,MAAM,MAAM,+BAA+B,CAAA;AAC5D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAA;AAE5D;;GAEG;AACH,cAAc,8BAA8B,CAAA;AAE5C;;;;;;GAMG;AACH,eAAO,MAAM,GAAG,EAAE,CAAC,EAAE,GAAG,KAAK,EAC3B,EAAE,MAAM,EAAE,eAAe,EAAE,KAAK,EAAE,EAAE,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC,KAC7D,MAAM,CAAC,MAAM,CAChB,aAAa,CAAC,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,EAClD,QAAQ,CAAC,cAAc,GAAG,QAAQ,EAClC,MAAM,CAAC,SAAS,GAAG,EAAE,CACF,CAAA;AAErB;;;;;;GAMG;AACH,eAAO,MAAM,KAAK,GAAI,CAAC,EACrB,SAAS,QAAQ,CAAC,eAAe,CAAC,CAAC,CAAC,KACnC,KAAK,CAAC,KAAK,CACZ,KAAK,EACL,QAAQ,CAAC,cAAc,GAAG,QAAQ,EAClC,MAAM,CAAC,SAAS,GAAG,CAAC,CACgB,CAAA"}
@@ -1,17 +1,23 @@
1
1
  import * as Layer from "effect/Layer";
2
2
  import * as Migrator from "effect/unstable/sql/Migrator";
3
3
  /**
4
- * @since 1.0.0
4
+ * @since 4.0.0
5
5
  */
6
6
  export * from "effect/unstable/sql/Migrator";
7
7
  /**
8
- * @category constructor
9
- * @since 1.0.0
8
+ * Runs SQL migrations for ClickHouse using the supplied migrator options and
9
+ * returns the applied migration IDs and names.
10
+ *
11
+ * @category constructors
12
+ * @since 4.0.0
10
13
  */
11
14
  export const run = /*#__PURE__*/Migrator.make({});
12
15
  /**
16
+ * Creates a layer that runs the configured ClickHouse migrations during layer
17
+ * construction and provides no services.
18
+ *
13
19
  * @category layers
14
- * @since 1.0.0
20
+ * @since 4.0.0
15
21
  */
16
22
  export const layer = options => Layer.effectDiscard(run(options));
17
23
  //# sourceMappingURL=ClickhouseMigrator.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ClickhouseMigrator.js","names":["Layer","Migrator","run","make","layer","options","effectDiscard"],"sources":["../src/ClickhouseMigrator.ts"],"sourcesContent":[null],"mappings":"AAIA,OAAO,KAAKA,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,QAAQ,MAAM,8BAA8B;AAIxD;;;AAGA,cAAc,8BAA8B;AAE5C;;;;AAIA,OAAO,MAAMC,GAAG,gBAMZD,QAAQ,CAACE,IAAI,CAAC,EAAE,CAAC;AAErB;;;;AAIA,OAAO,MAAMC,KAAK,GAChBC,OAAoC,IAKjCL,KAAK,CAACM,aAAa,CAACJ,GAAG,CAACG,OAAO,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"ClickhouseMigrator.js","names":["Layer","Migrator","run","make","layer","options","effectDiscard"],"sources":["../src/ClickhouseMigrator.ts"],"sourcesContent":[null],"mappings":"AAqBA,OAAO,KAAKA,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,QAAQ,MAAM,8BAA8B;AAIxD;;;AAGA,cAAc,8BAA8B;AAE5C;;;;;;;AAOA,OAAO,MAAMC,GAAG,gBAMZD,QAAQ,CAACE,IAAI,CAAC,EAAE,CAAC;AAErB;;;;;;;AAOA,OAAO,MAAMC,KAAK,GAChBC,OAAoC,IAKjCL,KAAK,CAACM,aAAa,CAACJ,GAAG,CAACG,OAAO,CAAC,CAAC","ignoreList":[]}
package/dist/index.d.ts CHANGED
@@ -1,12 +1,49 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * @since 4.0.0
3
3
  */
4
4
  /**
5
- * @since 1.0.0
5
+ * ClickHouse client implementation for Effect SQL, backed by
6
+ * `@clickhouse/client`.
7
+ *
8
+ * This module exposes constructors and layers for providing both the
9
+ * ClickHouse-specific `ClickhouseClient` service and the generic `SqlClient`
10
+ * service. It is intended for analytical application queries, migrations,
11
+ * background jobs, bulk inserts, and streaming reads that need Effect SQL query
12
+ * compilation, scoped lifecycle management, interruption, and consistent
13
+ * `SqlError` classification for ClickHouse failures.
14
+ *
15
+ * The client uses the ClickHouse HTTP client APIs for `query`, `command`, and
16
+ * `insert` operations. Regular queries read JSON result sets, `executeValues`
17
+ * requests `JSONCompact`, streams request `JSONEachRow`, and `insertQuery`
18
+ * defaults inserts to `JSONEachRow`. Interrupting an operation aborts the
19
+ * underlying HTTP request and attempts to kill the generated or supplied
20
+ * `query_id`. The statement compiler emits ClickHouse typed placeholders such
21
+ * as `{p1: Type}`; use `param` when the inferred type is too broad, and write
22
+ * ClickHouse-specific clauses such as engines, `SETTINGS`, `FORMAT`, or
23
+ * cluster directives explicitly.
24
+ *
25
+ * @since 4.0.0
6
26
  */
7
27
  export * as ClickhouseClient from "./ClickhouseClient.ts";
8
28
  /**
9
- * @since 1.0.0
29
+ * Utilities for applying Effect SQL migrations to ClickHouse databases.
30
+ *
31
+ * This module re-exports the shared `Migrator` loaders and error types, then
32
+ * provides `run` and `layer` helpers for applying ordered migrations through
33
+ * the current ClickHouse `SqlClient`. It is typically used during application
34
+ * startup, deployment, or integration tests that need to prepare analytical
35
+ * tables before dependent services begin reading or writing data.
36
+ *
37
+ * Applied migrations are stored in `effect_sql_migrations` by default and use
38
+ * the shared `<id>_<name>` loader convention. Only migrations with ids greater
39
+ * than the latest recorded id are run. ClickHouse schema changes often depend
40
+ * on engine, `ORDER BY`, database, and cluster settings, and many deployments
41
+ * rely on explicit `ON CLUSTER` clauses or coordinated rollout tooling. This
42
+ * adapter does not add a ClickHouse-specific table lock or schema dumper, so
43
+ * coordinate concurrent migrators and do not expect `schemaDirectory` to emit a
44
+ * ClickHouse schema snapshot.
45
+ *
46
+ * @since 4.0.0
10
47
  */
11
48
  export * as ClickhouseMigrator from "./ClickhouseMigrator.ts";
12
49
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;GAEG;AACH,OAAO,KAAK,gBAAgB,MAAM,uBAAuB,CAAA;AAEzD;;GAEG;AACH,OAAO,KAAK,kBAAkB,MAAM,yBAAyB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,OAAO,KAAK,gBAAgB,MAAM,uBAAuB,CAAA;AAEzD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,KAAK,kBAAkB,MAAM,yBAAyB,CAAA"}
package/dist/index.js CHANGED
@@ -1,13 +1,50 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * @since 4.0.0
3
3
  */
4
4
  // @barrel: Auto-generated exports. Do not edit manually.
5
5
  /**
6
- * @since 1.0.0
6
+ * ClickHouse client implementation for Effect SQL, backed by
7
+ * `@clickhouse/client`.
8
+ *
9
+ * This module exposes constructors and layers for providing both the
10
+ * ClickHouse-specific `ClickhouseClient` service and the generic `SqlClient`
11
+ * service. It is intended for analytical application queries, migrations,
12
+ * background jobs, bulk inserts, and streaming reads that need Effect SQL query
13
+ * compilation, scoped lifecycle management, interruption, and consistent
14
+ * `SqlError` classification for ClickHouse failures.
15
+ *
16
+ * The client uses the ClickHouse HTTP client APIs for `query`, `command`, and
17
+ * `insert` operations. Regular queries read JSON result sets, `executeValues`
18
+ * requests `JSONCompact`, streams request `JSONEachRow`, and `insertQuery`
19
+ * defaults inserts to `JSONEachRow`. Interrupting an operation aborts the
20
+ * underlying HTTP request and attempts to kill the generated or supplied
21
+ * `query_id`. The statement compiler emits ClickHouse typed placeholders such
22
+ * as `{p1: Type}`; use `param` when the inferred type is too broad, and write
23
+ * ClickHouse-specific clauses such as engines, `SETTINGS`, `FORMAT`, or
24
+ * cluster directives explicitly.
25
+ *
26
+ * @since 4.0.0
7
27
  */
8
28
  export * as ClickhouseClient from "./ClickhouseClient.js";
9
29
  /**
10
- * @since 1.0.0
30
+ * Utilities for applying Effect SQL migrations to ClickHouse databases.
31
+ *
32
+ * This module re-exports the shared `Migrator` loaders and error types, then
33
+ * provides `run` and `layer` helpers for applying ordered migrations through
34
+ * the current ClickHouse `SqlClient`. It is typically used during application
35
+ * startup, deployment, or integration tests that need to prepare analytical
36
+ * tables before dependent services begin reading or writing data.
37
+ *
38
+ * Applied migrations are stored in `effect_sql_migrations` by default and use
39
+ * the shared `<id>_<name>` loader convention. Only migrations with ids greater
40
+ * than the latest recorded id are run. ClickHouse schema changes often depend
41
+ * on engine, `ORDER BY`, database, and cluster settings, and many deployments
42
+ * rely on explicit `ON CLUSTER` clauses or coordinated rollout tooling. This
43
+ * adapter does not add a ClickHouse-specific table lock or schema dumper, so
44
+ * coordinate concurrent migrators and do not expect `schemaDirectory` to emit a
45
+ * ClickHouse schema snapshot.
46
+ *
47
+ * @since 4.0.0
11
48
  */
12
49
  export * as ClickhouseMigrator from "./ClickhouseMigrator.js";
13
50
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["ClickhouseClient","ClickhouseMigrator"],"sources":["../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAIA;AAEA;;;AAGA,OAAO,KAAKA,gBAAgB,MAAM,uBAAuB;AAEzD;;;AAGA,OAAO,KAAKC,kBAAkB,MAAM,yBAAyB","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["ClickhouseClient","ClickhouseMigrator"],"sources":["../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAIA;AAEA;;;;;;;;;;;;;;;;;;;;;;;AAuBA,OAAO,KAAKA,gBAAgB,MAAM,uBAAuB;AAEzD;;;;;;;;;;;;;;;;;;;;AAoBA,OAAO,KAAKC,kBAAkB,MAAM,yBAAyB","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effect/sql-clickhouse",
3
- "version": "4.0.0-beta.7",
3
+ "version": "4.0.0-beta.70",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "A Clickhouse toolkit for Effect",
@@ -43,15 +43,15 @@
43
43
  "provenance": true
44
44
  },
45
45
  "devDependencies": {
46
- "@effect/platform-node": "^4.0.0-beta.7",
47
- "effect": "^4.0.0-beta.7"
46
+ "@effect/platform-node": "^4.0.0-beta.70",
47
+ "effect": "^4.0.0-beta.70"
48
48
  },
49
49
  "peerDependencies": {
50
- "@effect/platform-node": "^4.0.0-beta.7",
51
- "effect": "^4.0.0-beta.7"
50
+ "effect": "^4.0.0-beta.70",
51
+ "@effect/platform-node": "^4.0.0-beta.70"
52
52
  },
53
53
  "dependencies": {
54
- "@clickhouse/client": "^1.16.0"
54
+ "@clickhouse/client": "^1.18.4"
55
55
  },
56
56
  "scripts": {
57
57
  "codegen": "effect-utils codegen",
@@ -1,21 +1,49 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * ClickHouse client implementation for Effect SQL, backed by
3
+ * `@clickhouse/client`.
4
+ *
5
+ * This module exposes constructors and layers for providing both the
6
+ * ClickHouse-specific `ClickhouseClient` service and the generic `SqlClient`
7
+ * service. It is intended for analytical application queries, migrations,
8
+ * background jobs, bulk inserts, and streaming reads that need Effect SQL query
9
+ * compilation, scoped lifecycle management, interruption, and consistent
10
+ * `SqlError` classification for ClickHouse failures.
11
+ *
12
+ * The client uses the ClickHouse HTTP client APIs for `query`, `command`, and
13
+ * `insert` operations. Regular queries read JSON result sets, `executeValues`
14
+ * requests `JSONCompact`, streams request `JSONEachRow`, and `insertQuery`
15
+ * defaults inserts to `JSONEachRow`. Interrupting an operation aborts the
16
+ * underlying HTTP request and attempts to kill the generated or supplied
17
+ * `query_id`. The statement compiler emits ClickHouse typed placeholders such
18
+ * as `{p1: Type}`; use `param` when the inferred type is too broad, and write
19
+ * ClickHouse-specific clauses such as engines, `SETTINGS`, `FORMAT`, or
20
+ * cluster directives explicitly.
21
+ *
22
+ * @since 4.0.0
3
23
  */
4
24
  import * as Clickhouse from "@clickhouse/client"
5
25
  import * as NodeStream from "@effect/platform-node/NodeStream"
6
26
  import * as Config from "effect/Config"
27
+ import * as Context from "effect/Context"
7
28
  import * as Duration from "effect/Duration"
8
29
  import * as Effect from "effect/Effect"
9
30
  import * as Fiber from "effect/Fiber"
10
31
  import { dual } from "effect/Function"
11
32
  import * as Layer from "effect/Layer"
12
33
  import type * as Scope from "effect/Scope"
13
- import * as ServiceMap from "effect/ServiceMap"
14
34
  import * as Stream from "effect/Stream"
15
35
  import * as Reactivity from "effect/unstable/reactivity/Reactivity"
16
36
  import * as Client from "effect/unstable/sql/SqlClient"
17
37
  import type { Connection } from "effect/unstable/sql/SqlConnection"
18
- import { SqlError } from "effect/unstable/sql/SqlError"
38
+ import {
39
+ AuthenticationError,
40
+ AuthorizationError,
41
+ ConnectionError,
42
+ SqlError,
43
+ SqlSyntaxError,
44
+ StatementTimeoutError,
45
+ UnknownError
46
+ } from "effect/unstable/sql/SqlError"
19
47
  import * as Statement from "effect/unstable/sql/Statement"
20
48
  import * as Crypto from "node:crypto"
21
49
  import type { Readable } from "node:stream"
@@ -23,21 +51,71 @@ import type { Readable } from "node:stream"
23
51
  const ATTR_DB_SYSTEM_NAME = "db.system.name"
24
52
  const ATTR_DB_NAMESPACE = "db.namespace"
25
53
 
54
+ const clickhouseCodeFromCause = (cause: unknown): number | undefined => {
55
+ if (typeof cause !== "object" || cause === null || !("code" in cause)) {
56
+ return undefined
57
+ }
58
+ const code = cause.code
59
+ if (typeof code === "number") {
60
+ return code
61
+ }
62
+ if (typeof code === "string") {
63
+ const parsed = Number(code)
64
+ return Number.isNaN(parsed) ? undefined : parsed
65
+ }
66
+ return undefined
67
+ }
68
+
69
+ const clickhouseSyntaxErrorCodes = new Set([36, 60, 62, 242])
70
+
71
+ const classifyError = (
72
+ cause: unknown,
73
+ message: string,
74
+ operation: string,
75
+ fallback: "connection" | "unknown" = "unknown"
76
+ ) => {
77
+ const props = { cause, message, operation }
78
+ const code = clickhouseCodeFromCause(cause)
79
+ if (code !== undefined) {
80
+ if (code === 516) {
81
+ return new AuthenticationError(props)
82
+ }
83
+ if (code === 497) {
84
+ return new AuthorizationError(props)
85
+ }
86
+ if (clickhouseSyntaxErrorCodes.has(code)) {
87
+ return new SqlSyntaxError(props)
88
+ }
89
+ if (code === 159 || code === 469) {
90
+ return new StatementTimeoutError(props)
91
+ }
92
+ }
93
+ return fallback === "connection" ? new ConnectionError(props) : new UnknownError(props)
94
+ }
95
+
26
96
  /**
27
- * @category type ids
28
- * @since 1.0.0
97
+ * Unique runtime identifier used to tag `ClickhouseClient` values.
98
+ *
99
+ * @category type IDs
100
+ * @since 4.0.0
29
101
  */
30
102
  export const TypeId: TypeId = "~@effect/sql-clickhouse/ClickhouseClient"
31
103
 
32
104
  /**
33
- * @category type ids
34
- * @since 1.0.0
105
+ * Type-level literal for the `ClickhouseClient` runtime identifier.
106
+ *
107
+ * @category type IDs
108
+ * @since 4.0.0
35
109
  */
36
110
  export type TypeId = "~@effect/sql-clickhouse/ClickhouseClient"
37
111
 
38
112
  /**
113
+ * ClickHouse-specific `SqlClient` extension with access to its configuration,
114
+ * typed parameter fragments, command-mode execution, insert queries, and
115
+ * per-effect query ID and ClickHouse settings.
116
+ *
39
117
  * @category models
40
- * @since 1.0.0
118
+ * @since 4.0.0
41
119
  */
42
120
  export interface ClickhouseClient extends Client.SqlClient {
43
121
  readonly [TypeId]: TypeId
@@ -65,14 +143,20 @@ export interface ClickhouseClient extends Client.SqlClient {
65
143
  }
66
144
 
67
145
  /**
146
+ * Context service tag for accessing the active `ClickhouseClient`.
147
+ *
68
148
  * @category tags
69
- * @since 1.0.0
149
+ * @since 4.0.0
70
150
  */
71
- export const ClickhouseClient = ServiceMap.Service<ClickhouseClient>("@effect/sql-clickhouse/ClickhouseClient")
151
+ export const ClickhouseClient = Context.Service<ClickhouseClient>("@effect/sql-clickhouse/ClickhouseClient")
72
152
 
73
153
  /**
154
+ * Configuration for creating a ClickHouse client, combining
155
+ * `@clickhouse/client` options with optional span attributes and query/result
156
+ * name transforms.
157
+ *
74
158
  * @category constructors
75
- * @since 1.0.0
159
+ * @since 4.0.0
76
160
  */
77
161
  export interface ClickhouseClientConfig extends Clickhouse.ClickHouseClientConfigOptions {
78
162
  readonly spanAttributes?: Record<string, unknown> | undefined
@@ -81,8 +165,12 @@ export interface ClickhouseClientConfig extends Clickhouse.ClickHouseClientConfi
81
165
  }
82
166
 
83
167
  /**
168
+ * Creates a scoped `ClickhouseClient`, verifies connectivity with `SELECT 1`,
169
+ * closes the underlying client when the scope ends, maps ClickHouse failures
170
+ * to `SqlError`, and aborts plus kills in-flight queries when interrupted.
171
+ *
84
172
  * @category constructors
85
- * @since 1.0.0
173
+ * @since 4.0.0
86
174
  */
87
175
  export const make = (
88
176
  options: ClickhouseClientConfig
@@ -98,17 +186,21 @@ export const make = (
98
186
  yield* Effect.acquireRelease(
99
187
  Effect.tryPromise({
100
188
  try: () => client.exec({ query: "SELECT 1" }),
101
- catch: (cause) => new SqlError({ cause, message: "ClickhouseClient: Failed to connect" })
189
+ catch: (cause) =>
190
+ new SqlError({ reason: classifyError(cause, "ClickhouseClient: Failed to connect", "connect", "connection") })
102
191
  }),
103
192
  () => Effect.promise(() => client.close())
104
193
  ).pipe(
105
194
  Effect.timeoutOrElse({
106
195
  duration: Duration.seconds(5),
107
- onTimeout: () =>
196
+ orElse: () =>
108
197
  Effect.fail(
109
198
  new SqlError({
110
- message: "ClickhouseClient: Connection timeout",
111
- cause: new Error("connection timeout")
199
+ reason: new ConnectionError({
200
+ message: "ClickhouseClient: Connection timeout",
201
+ cause: new Error("connection timeout"),
202
+ operation: "connect"
203
+ })
112
204
  })
113
205
  )
114
206
  })
@@ -140,7 +232,12 @@ export const make = (
140
232
  clickhouse_settings: settings
141
233
  }).then(
142
234
  (result) => resume(Effect.succeed(result)),
143
- (cause) => resume(Effect.fail(new SqlError({ cause, message: "Failed to execute statement" })))
235
+ (cause) =>
236
+ resume(
237
+ Effect.fail(
238
+ new SqlError({ reason: classifyError(cause, "Failed to execute statement", "execute") })
239
+ )
240
+ )
144
241
  )
145
242
  } else {
146
243
  this.conn.query({
@@ -152,7 +249,12 @@ export const make = (
152
249
  format
153
250
  }).then(
154
251
  (result) => resume(Effect.succeed(result)),
155
- (cause) => resume(Effect.fail(new SqlError({ cause, message: "Failed to execute statement" })))
252
+ (cause) =>
253
+ resume(
254
+ Effect.fail(
255
+ new SqlError({ reason: classifyError(cause, "Failed to execute statement", "execute") })
256
+ )
257
+ )
156
258
  )
157
259
  }
158
260
  return Effect.suspend(() => {
@@ -209,7 +311,7 @@ export const make = (
209
311
  }
210
312
  return NodeStream.fromReadable<ReadonlyArray<Clickhouse.Row<any, "JSONEachRow">>, SqlError>({
211
313
  evaluate: () => result.stream() as any,
212
- onError: (cause) => new SqlError({ cause, message: "Failed to execute stream" })
314
+ onError: (cause) => new SqlError({ reason: classifyError(cause, "Failed to execute stream", "stream") })
213
315
  })
214
316
  }),
215
317
  Stream.unwrap,
@@ -223,7 +325,7 @@ export const make = (
223
325
  }
224
326
  return Effect.tryPromise({
225
327
  try: () => Promise.all(promises).then((rows) => transformRows ? transformRows(rows) : rows),
226
- catch: (cause) => new SqlError({ cause, message: "Failed to parse row" })
328
+ catch: (cause) => new SqlError({ reason: classifyError(cause, "Failed to parse row", "parseRow") })
227
329
  })
228
330
  }),
229
331
  Stream.flattenIterable
@@ -272,7 +374,8 @@ export const make = (
272
374
  clickhouse_settings: settings
273
375
  }).then(
274
376
  (result) => resume(Effect.succeed(result)),
275
- (cause) => resume(Effect.fail(new SqlError({ cause, message: "Failed to insert data" })))
377
+ (cause) =>
378
+ resume(Effect.fail(new SqlError({ reason: classifyError(cause, "Failed to insert data", "insert") })))
276
379
  )
277
380
  return Effect.suspend(() => {
278
381
  controller.abort()
@@ -280,25 +383,29 @@ export const make = (
280
383
  })
281
384
  })
282
385
  },
283
- withQueryId: dual(2, <A, E, R>(effect: Effect.Effect<A, E, R>, queryId: string) =>
284
- Effect.provideService(effect, QueryId, queryId)),
386
+ withQueryId: dual(
387
+ 2,
388
+ <A, E, R>(effect: Effect.Effect<A, E, R>, queryId: string) => Effect.provideService(effect, QueryId, queryId)
389
+ ),
285
390
  withClickhouseSettings: dual(
286
391
  2,
287
392
  <A, E, R>(
288
393
  effect: Effect.Effect<A, E, R>,
289
394
  settings: NonNullable<Clickhouse.BaseQueryParams["clickhouse_settings"]>
290
- ) =>
291
- Effect.provideService(effect, ClickhouseSettings, settings)
395
+ ) => Effect.provideService(effect, ClickhouseSettings, settings)
292
396
  )
293
397
  }
294
398
  )
295
399
  })
296
400
 
297
401
  /**
298
- * @category References
299
- * @since 1.0.0
402
+ * Fiber reference read by the low-level ClickHouse connection to choose query
403
+ * or command execution for statements; defaults to `query`.
404
+ *
405
+ * @category references
406
+ * @since 4.0.0
300
407
  */
301
- export const ClientMethod = ServiceMap.Reference<"query" | "command" | "insert">(
408
+ export const ClientMethod = Context.Reference<"query" | "command" | "insert">(
302
409
  "@effect/sql-clickhouse/ClickhouseClient/ClientMethod",
303
410
  {
304
411
  defaultValue: () => "query"
@@ -306,55 +413,67 @@ export const ClientMethod = ServiceMap.Reference<"query" | "command" | "insert">
306
413
  )
307
414
 
308
415
  /**
309
- * @category References
310
- * @since 1.0.0
416
+ * Fiber reference for the ClickHouse `query_id` applied to queries and
417
+ * inserts; a random UUID is generated when no query ID is set.
418
+ *
419
+ * @category references
420
+ * @since 4.0.0
311
421
  */
312
- export const QueryId = ServiceMap.Reference<string | undefined>(
422
+ export const QueryId = Context.Reference<string | undefined>(
313
423
  "@effect/sql-clickhouse/ClickhouseClient/QueryId",
314
424
  { defaultValue: () => undefined }
315
425
  )
316
426
 
317
427
  /**
318
- * @category References
319
- * @since 1.0.0
428
+ * Fiber reference containing ClickHouse settings to attach to queries,
429
+ * commands, and inserts.
430
+ *
431
+ * @category references
432
+ * @since 4.0.0
320
433
  */
321
- export const ClickhouseSettings: ServiceMap.Reference<
434
+ export const ClickhouseSettings: Context.Reference<
322
435
  NonNullable<Clickhouse.BaseQueryParams["clickhouse_settings"]>
323
- > = ServiceMap.Reference("@effect/sql-clickhouse/ClickhouseClient/ClickhouseSettings", {
436
+ > = Context.Reference("@effect/sql-clickhouse/ClickhouseClient/ClickhouseSettings", {
324
437
  defaultValue: () => ({})
325
438
  })
326
439
 
327
440
  /**
441
+ * Provides both `ClickhouseClient` and generic `SqlClient` services from a
442
+ * `Config`-backed ClickHouse client configuration.
443
+ *
328
444
  * @category layers
329
- * @since 1.0.0
445
+ * @since 4.0.0
330
446
  */
331
447
  export const layerConfig: (
332
448
  config: Config.Wrap<ClickhouseClientConfig>
333
449
  ) => Layer.Layer<ClickhouseClient | Client.SqlClient, Config.ConfigError | SqlError> = (
334
450
  config: Config.Wrap<ClickhouseClientConfig>
335
451
  ): Layer.Layer<ClickhouseClient | Client.SqlClient, Config.ConfigError | SqlError> =>
336
- Layer.effectServices(
337
- Config.unwrap(config).asEffect().pipe(
452
+ Layer.effectContext(
453
+ Config.unwrap(config).pipe(
338
454
  Effect.flatMap(make),
339
455
  Effect.map((client) =>
340
- ServiceMap.make(ClickhouseClient, client).pipe(
341
- ServiceMap.add(Client.SqlClient, client)
456
+ Context.make(ClickhouseClient, client).pipe(
457
+ Context.add(Client.SqlClient, client)
342
458
  )
343
459
  )
344
460
  )
345
461
  ).pipe(Layer.provide(Reactivity.layer))
346
462
 
347
463
  /**
464
+ * Provides both `ClickhouseClient` and generic `SqlClient` services from a
465
+ * ClickHouse client configuration.
466
+ *
348
467
  * @category layers
349
- * @since 1.0.0
468
+ * @since 4.0.0
350
469
  */
351
470
  export const layer = (
352
471
  config: ClickhouseClientConfig
353
472
  ): Layer.Layer<ClickhouseClient | Client.SqlClient, Config.ConfigError | SqlError> =>
354
- Layer.effectServices(
473
+ Layer.effectContext(
355
474
  Effect.map(make(config), (client) =>
356
- ServiceMap.make(ClickhouseClient, client).pipe(
357
- ServiceMap.add(Client.SqlClient, client)
475
+ Context.make(ClickhouseClient, client).pipe(
476
+ Context.add(Client.SqlClient, client)
358
477
  ))
359
478
  ).pipe(Layer.provide(Reactivity.layer))
360
479
 
@@ -384,8 +503,12 @@ const typeFromUnknown = (value: unknown): string => {
384
503
  }
385
504
 
386
505
  /**
506
+ * Creates the SQL statement compiler for ClickHouse, emitting typed
507
+ * `{pN: Type}` placeholders and escaping identifiers with an optional query
508
+ * name transform.
509
+ *
387
510
  * @category compiler
388
- * @since 1.0.0
511
+ * @since 4.0.0
389
512
  */
390
513
  export const makeCompiler = (transform?: (_: string) => string) =>
391
514
  Statement.makeCompiler<ClickhouseCustom>({
@@ -411,14 +534,17 @@ export const makeCompiler = (transform?: (_: string) => string) =>
411
534
  const escape = Statement.defaultEscape("\"")
412
535
 
413
536
  /**
537
+ * Custom SQL fragment type used for ClickHouse typed parameters created by
538
+ * `ClickhouseClient.param`.
539
+ *
414
540
  * @category custom types
415
- * @since 1.0.0
541
+ * @since 4.0.0
416
542
  */
417
543
  export type ClickhouseCustom = ClickhouseParam
418
544
 
419
545
  /**
420
546
  * @category custom types
421
- * @since 1.0.0
547
+ * @since 4.0.0
422
548
  */
423
549
  interface ClickhouseParam extends Statement.Custom<"ClickhouseParam", string, unknown> {}
424
550
 
@@ -1,5 +1,22 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * Utilities for applying Effect SQL migrations to ClickHouse databases.
3
+ *
4
+ * This module re-exports the shared `Migrator` loaders and error types, then
5
+ * provides `run` and `layer` helpers for applying ordered migrations through
6
+ * the current ClickHouse `SqlClient`. It is typically used during application
7
+ * startup, deployment, or integration tests that need to prepare analytical
8
+ * tables before dependent services begin reading or writing data.
9
+ *
10
+ * Applied migrations are stored in `effect_sql_migrations` by default and use
11
+ * the shared `<id>_<name>` loader convention. Only migrations with ids greater
12
+ * than the latest recorded id are run. ClickHouse schema changes often depend
13
+ * on engine, `ORDER BY`, database, and cluster settings, and many deployments
14
+ * rely on explicit `ON CLUSTER` clauses or coordinated rollout tooling. This
15
+ * adapter does not add a ClickHouse-specific table lock or schema dumper, so
16
+ * coordinate concurrent migrators and do not expect `schemaDirectory` to emit a
17
+ * ClickHouse schema snapshot.
18
+ *
19
+ * @since 4.0.0
3
20
  */
4
21
  import type * as Effect from "effect/Effect"
5
22
  import * as Layer from "effect/Layer"
@@ -8,13 +25,16 @@ import type * as Client from "effect/unstable/sql/SqlClient"
8
25
  import type { SqlError } from "effect/unstable/sql/SqlError"
9
26
 
10
27
  /**
11
- * @since 1.0.0
28
+ * @since 4.0.0
12
29
  */
13
30
  export * from "effect/unstable/sql/Migrator"
14
31
 
15
32
  /**
16
- * @category constructor
17
- * @since 1.0.0
33
+ * Runs SQL migrations for ClickHouse using the supplied migrator options and
34
+ * returns the applied migration IDs and names.
35
+ *
36
+ * @category constructors
37
+ * @since 4.0.0
18
38
  */
19
39
  export const run: <R2 = never>(
20
40
  { loader, schemaDirectory, table }: Migrator.MigratorOptions<R2>
@@ -25,8 +45,11 @@ export const run: <R2 = never>(
25
45
  > = Migrator.make({})
26
46
 
27
47
  /**
48
+ * Creates a layer that runs the configured ClickHouse migrations during layer
49
+ * construction and provides no services.
50
+ *
28
51
  * @category layers
29
- * @since 1.0.0
52
+ * @since 4.0.0
30
53
  */
31
54
  export const layer = <R>(
32
55
  options: Migrator.MigratorOptions<R>
package/src/index.ts CHANGED
@@ -1,15 +1,52 @@
1
1
  /**
2
- * @since 1.0.0
2
+ * @since 4.0.0
3
3
  */
4
4
 
5
5
  // @barrel: Auto-generated exports. Do not edit manually.
6
6
 
7
7
  /**
8
- * @since 1.0.0
8
+ * ClickHouse client implementation for Effect SQL, backed by
9
+ * `@clickhouse/client`.
10
+ *
11
+ * This module exposes constructors and layers for providing both the
12
+ * ClickHouse-specific `ClickhouseClient` service and the generic `SqlClient`
13
+ * service. It is intended for analytical application queries, migrations,
14
+ * background jobs, bulk inserts, and streaming reads that need Effect SQL query
15
+ * compilation, scoped lifecycle management, interruption, and consistent
16
+ * `SqlError` classification for ClickHouse failures.
17
+ *
18
+ * The client uses the ClickHouse HTTP client APIs for `query`, `command`, and
19
+ * `insert` operations. Regular queries read JSON result sets, `executeValues`
20
+ * requests `JSONCompact`, streams request `JSONEachRow`, and `insertQuery`
21
+ * defaults inserts to `JSONEachRow`. Interrupting an operation aborts the
22
+ * underlying HTTP request and attempts to kill the generated or supplied
23
+ * `query_id`. The statement compiler emits ClickHouse typed placeholders such
24
+ * as `{p1: Type}`; use `param` when the inferred type is too broad, and write
25
+ * ClickHouse-specific clauses such as engines, `SETTINGS`, `FORMAT`, or
26
+ * cluster directives explicitly.
27
+ *
28
+ * @since 4.0.0
9
29
  */
10
30
  export * as ClickhouseClient from "./ClickhouseClient.ts"
11
31
 
12
32
  /**
13
- * @since 1.0.0
33
+ * Utilities for applying Effect SQL migrations to ClickHouse databases.
34
+ *
35
+ * This module re-exports the shared `Migrator` loaders and error types, then
36
+ * provides `run` and `layer` helpers for applying ordered migrations through
37
+ * the current ClickHouse `SqlClient`. It is typically used during application
38
+ * startup, deployment, or integration tests that need to prepare analytical
39
+ * tables before dependent services begin reading or writing data.
40
+ *
41
+ * Applied migrations are stored in `effect_sql_migrations` by default and use
42
+ * the shared `<id>_<name>` loader convention. Only migrations with ids greater
43
+ * than the latest recorded id are run. ClickHouse schema changes often depend
44
+ * on engine, `ORDER BY`, database, and cluster settings, and many deployments
45
+ * rely on explicit `ON CLUSTER` clauses or coordinated rollout tooling. This
46
+ * adapter does not add a ClickHouse-specific table lock or schema dumper, so
47
+ * coordinate concurrent migrators and do not expect `schemaDirectory` to emit a
48
+ * ClickHouse schema snapshot.
49
+ *
50
+ * @since 4.0.0
14
51
  */
15
52
  export * as ClickhouseMigrator from "./ClickhouseMigrator.ts"