@effect/sql-clickhouse 4.0.0-beta.99 → 4.0.0-rc.108

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.
Files changed (87) hide show
  1. package/AGENTS.md +381 -0
  2. package/CLAUDE.md +381 -0
  3. package/README.md +10 -3
  4. package/ai-docs/README.md +44 -0
  5. package/ai-docs/package.json +36 -0
  6. package/ai-docs/src/01_effect/01_basics/01_effect-gen.ts +30 -0
  7. package/ai-docs/src/01_effect/01_basics/02_effect-fn.ts +39 -0
  8. package/ai-docs/src/01_effect/01_basics/10_creating-effects.ts +74 -0
  9. package/ai-docs/src/01_effect/01_basics/index.md +5 -0
  10. package/ai-docs/src/01_effect/02_schema/10_schema-basics.ts +43 -0
  11. package/ai-docs/src/01_effect/02_schema/index.md +7 -0
  12. package/ai-docs/src/01_effect/03_services/01_service.ts +45 -0
  13. package/ai-docs/src/01_effect/03_services/10_reference.ts +10 -0
  14. package/ai-docs/src/01_effect/03_services/20_layer-composition.ts +70 -0
  15. package/ai-docs/src/01_effect/03_services/20_layer-unwrap.ts +66 -0
  16. package/ai-docs/src/01_effect/03_services/index.md +5 -0
  17. package/ai-docs/src/01_effect/04_errors/01_error-handling.ts +30 -0
  18. package/ai-docs/src/01_effect/04_errors/10_catch-tags.ts +24 -0
  19. package/ai-docs/src/01_effect/04_errors/20_reason-errors.ts +64 -0
  20. package/ai-docs/src/01_effect/04_errors/index.md +1 -0
  21. package/ai-docs/src/01_effect/05_resources/10_acquire-release.ts +105 -0
  22. package/ai-docs/src/01_effect/05_resources/20_layer-side-effects.ts +31 -0
  23. package/ai-docs/src/01_effect/05_resources/30_layer-map.ts +86 -0
  24. package/ai-docs/src/01_effect/05_resources/index.md +3 -0
  25. package/ai-docs/src/01_effect/06_running/10_run-main.ts +30 -0
  26. package/ai-docs/src/01_effect/06_running/20_layer-launch.ts +27 -0
  27. package/ai-docs/src/01_effect/06_running/index.md +1 -0
  28. package/ai-docs/src/01_effect/07_pubsub/10_pubsub.ts +56 -0
  29. package/ai-docs/src/01_effect/07_pubsub/index.md +3 -0
  30. package/ai-docs/src/03_stream/10_creating-streams.ts +103 -0
  31. package/ai-docs/src/03_stream/20_consuming-streams.ts +137 -0
  32. package/ai-docs/src/03_stream/30_encoding.ts +165 -0
  33. package/ai-docs/src/03_stream/index.md +4 -0
  34. package/ai-docs/src/04_integration/10_managed-runtime.ts +129 -0
  35. package/ai-docs/src/04_integration/index.md +5 -0
  36. package/ai-docs/src/05_batching/10_request-resolver.ts +89 -0
  37. package/ai-docs/src/05_batching/index.md +3 -0
  38. package/ai-docs/src/06_schedule/10_schedules.ts +110 -0
  39. package/ai-docs/src/06_schedule/index.md +3 -0
  40. package/ai-docs/src/07_datetime/10_creating-and-formatting.ts +30 -0
  41. package/ai-docs/src/07_datetime/20_time-zones.ts +44 -0
  42. package/ai-docs/src/07_datetime/index.md +5 -0
  43. package/ai-docs/src/08_observability/10_logging.ts +66 -0
  44. package/ai-docs/src/08_observability/20_otlp-tracing.ts +95 -0
  45. package/ai-docs/src/08_observability/index.md +7 -0
  46. package/ai-docs/src/09_testing/10_effect-tests.ts +55 -0
  47. package/ai-docs/src/09_testing/20_layer-tests.ts +138 -0
  48. package/ai-docs/src/09_testing/index.md +1 -0
  49. package/ai-docs/src/10_predicate/01_basics.ts +14 -0
  50. package/ai-docs/src/10_predicate/index.md +9 -0
  51. package/ai-docs/src/50_http-client/10_basics.ts +102 -0
  52. package/ai-docs/src/50_http-client/index.md +3 -0
  53. package/ai-docs/src/51_http-server/10_basics.ts +116 -0
  54. package/ai-docs/src/51_http-server/fixtures/api/Api.ts +14 -0
  55. package/ai-docs/src/51_http-server/fixtures/api/Authorization.ts +36 -0
  56. package/ai-docs/src/51_http-server/fixtures/api/System.ts +10 -0
  57. package/ai-docs/src/51_http-server/fixtures/api/Users.ts +91 -0
  58. package/ai-docs/src/51_http-server/fixtures/domain/User.ts +12 -0
  59. package/ai-docs/src/51_http-server/fixtures/domain/UserErrors.ts +22 -0
  60. package/ai-docs/src/51_http-server/fixtures/server/Authorization.ts +36 -0
  61. package/ai-docs/src/51_http-server/fixtures/server/Users/http.ts +71 -0
  62. package/ai-docs/src/51_http-server/fixtures/server/Users.ts +62 -0
  63. package/ai-docs/src/51_http-server/index.md +3 -0
  64. package/ai-docs/src/60_child-process/10_working-with-child-processes.ts +117 -0
  65. package/ai-docs/src/60_child-process/index.md +3 -0
  66. package/ai-docs/src/70_cli/10_basics.ts +136 -0
  67. package/ai-docs/src/70_cli/index.md +5 -0
  68. package/ai-docs/src/71_ai/10_language-model.ts +156 -0
  69. package/ai-docs/src/71_ai/20_tools.ts +226 -0
  70. package/ai-docs/src/71_ai/30_chat.ts +158 -0
  71. package/ai-docs/src/71_ai/fixtures/domain/LaunchPlan.ts +9 -0
  72. package/ai-docs/src/71_ai/index.md +5 -0
  73. package/ai-docs/src/80_cluster/10_entities.ts +97 -0
  74. package/ai-docs/src/80_cluster/index.md +4 -0
  75. package/ai-docs/src/index.md +10 -0
  76. package/ai-docs/tsconfig.json +24 -0
  77. package/dist/ClickhouseClient.d.ts +8 -8
  78. package/dist/ClickhouseClient.d.ts.map +1 -1
  79. package/dist/ClickhouseClient.js +22 -11
  80. package/dist/ClickhouseClient.js.map +1 -1
  81. package/dist/ClickhouseMigrator.d.ts +1 -1
  82. package/dist/ClickhouseMigrator.js +1 -1
  83. package/dist/ClickhouseMigrator.js.map +1 -1
  84. package/dist/index.js.map +1 -1
  85. package/package.json +11 -9
  86. package/src/ClickhouseClient.ts +35 -26
  87. package/src/ClickhouseMigrator.ts +1 -1
@@ -104,7 +104,7 @@ export type TypeId = "~@effect/sql-clickhouse/ClickhouseClient"
104
104
  * typed parameter fragments, command-mode execution, insert queries, and
105
105
  * per-effect query ID and ClickHouse settings.
106
106
  *
107
- * @category models
107
+ * @category services
108
108
  * @since 4.0.0
109
109
  */
110
110
  export interface ClickhouseClient extends Client.SqlClient {
@@ -149,7 +149,7 @@ export const ClickhouseClient = Context.Service<ClickhouseClient>("@effect/sql-c
149
149
  * `@clickhouse/client` options with optional span attributes and query/result
150
150
  * name transforms.
151
151
  *
152
- * @category constructors
152
+ * @category models
153
153
  * @since 4.0.0
154
154
  */
155
155
  export interface ClickhouseClientConfig extends Clickhouse.ClickHouseClientConfigOptions {
@@ -175,16 +175,16 @@ export const make = (
175
175
  ? Statement.defaultTransforms(options.transformResultNames).array
176
176
  : undefined
177
177
 
178
- const client = Clickhouse.createClient(options)
178
+ const client = yield* Effect.acquireRelease(
179
+ Effect.sync(() => Clickhouse.createClient(options)),
180
+ (client) => Effect.promise(() => client.close())
181
+ )
179
182
 
180
- yield* Effect.acquireRelease(
181
- Effect.tryPromise({
182
- try: () => client.exec({ query: "SELECT 1" }),
183
- catch: (cause) =>
184
- new SqlError({ reason: classifyError(cause, "ClickhouseClient: Failed to connect", "connect", "connection") })
185
- }),
186
- () => Effect.promise(() => client.close())
187
- ).pipe(
183
+ yield* Effect.tryPromise({
184
+ try: () => client.exec({ query: "SELECT 1" }),
185
+ catch: (cause) =>
186
+ new SqlError({ reason: classifyError(cause, "ClickhouseClient: Failed to connect", "connect", "connection") })
187
+ }).pipe(
188
188
  Effect.timeoutOrElse({
189
189
  duration: Duration.seconds(5),
190
190
  orElse: () =>
@@ -253,7 +253,12 @@ export const make = (
253
253
  }
254
254
  return Effect.suspend(() => {
255
255
  controller.abort()
256
- return Effect.promise(() => this.conn.command({ query: `KILL QUERY WHERE query_id = '${queryId}'` }))
256
+ return Effect.promise(() =>
257
+ this.conn.command({
258
+ query: "KILL QUERY WHERE query_id = {queryId:String}",
259
+ query_params: { queryId }
260
+ })
261
+ )
257
262
  })
258
263
  })
259
264
  })
@@ -263,12 +268,11 @@ export const make = (
263
268
  return this.runRaw(sql, params, format).pipe(
264
269
  Effect.flatMap((result) => {
265
270
  if ("json" in result) {
266
- return Effect.promise(() =>
267
- result.json().then(
268
- (result) => "data" in result ? result.data : result as any,
269
- () => []
270
- )
271
- )
271
+ return Effect.tryPromise({
272
+ try: () => result.json().then((result) => "data" in result ? result.data : result as any),
273
+ catch: (cause) =>
274
+ new SqlError({ reason: classifyError(cause, "Failed to parse result", "parseResult") })
275
+ })
272
276
  }
273
277
  return Effect.succeed([])
274
278
  })
@@ -376,7 +380,12 @@ export const make = (
376
380
  )
377
381
  return Effect.suspend(() => {
378
382
  controller.abort()
379
- return Effect.promise(() => client.command({ query: `KILL QUERY WHERE query_id = '${queryId}'` }))
383
+ return Effect.promise(() =>
384
+ client.command({
385
+ query: "KILL QUERY WHERE query_id = {queryId:String}",
386
+ query_params: { queryId }
387
+ })
388
+ )
380
389
  })
381
390
  })
382
391
  },
@@ -399,7 +408,7 @@ export const make = (
399
408
  * Fiber reference read by the low-level ClickHouse connection to choose query
400
409
  * or command execution for statements; defaults to `query`.
401
410
  *
402
- * @category references
411
+ * @category services
403
412
  * @since 4.0.0
404
413
  */
405
414
  export const ClientMethod = Context.Reference<"query" | "command" | "insert">(
@@ -413,7 +422,7 @@ export const ClientMethod = Context.Reference<"query" | "command" | "insert">(
413
422
  * Fiber reference for the ClickHouse `query_id` applied to queries and
414
423
  * inserts; a random UUID is generated when no query ID is set.
415
424
  *
416
- * @category references
425
+ * @category services
417
426
  * @since 4.0.0
418
427
  */
419
428
  export const QueryId = Context.Reference<string | undefined>(
@@ -425,7 +434,7 @@ export const QueryId = Context.Reference<string | undefined>(
425
434
  * Fiber reference containing ClickHouse settings to attach to queries,
426
435
  * commands, and inserts.
427
436
  *
428
- * @category references
437
+ * @category services
429
438
  * @since 4.0.0
430
439
  */
431
440
  export const ClickhouseSettings: Context.Reference<
@@ -484,7 +493,7 @@ const typeFromUnknown = (value: unknown): string => {
484
493
  }
485
494
  switch (typeof value) {
486
495
  case "number":
487
- return "Decimal"
496
+ return "Float64"
488
497
  case "bigint":
489
498
  return "Int64"
490
499
  case "boolean":
@@ -504,7 +513,7 @@ const typeFromUnknown = (value: unknown): string => {
504
513
  * `{pN: Type}` placeholders and escaping identifiers with an optional query
505
514
  * name transform.
506
515
  *
507
- * @category compiler
516
+ * @category constructors
508
517
  * @since 4.0.0
509
518
  */
510
519
  export const makeCompiler = (transform?: (_: string) => string) =>
@@ -534,13 +543,13 @@ const escape = Statement.defaultEscape("\"")
534
543
  * Custom SQL fragment type used for ClickHouse typed parameters created by
535
544
  * `ClickhouseClient.param`.
536
545
  *
537
- * @category custom types
546
+ * @category models
538
547
  * @since 4.0.0
539
548
  */
540
549
  export type ClickhouseCustom = ClickhouseParam
541
550
 
542
551
  /**
543
- * @category custom types
552
+ * @category models
544
553
  * @since 4.0.0
545
554
  */
546
555
  interface ClickhouseParam extends Statement.Custom<"ClickhouseParam", string, unknown> {}
@@ -24,7 +24,7 @@ export * from "effect/unstable/sql/Migrator"
24
24
  * Runs SQL migrations for ClickHouse using the supplied migrator options and
25
25
  * returns the applied migration IDs and names.
26
26
  *
27
- * @category constructors
27
+ * @category running
28
28
  * @since 4.0.0
29
29
  */
30
30
  export const run: <R2 = never>(