@clickhouse/client 0.0.4 → 0.0.6

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.
package/README.md CHANGED
@@ -4,8 +4,11 @@
4
4
  </p>
5
5
  <br/>
6
6
  <p align="center">
7
- <a href="https://github.com/ClickHouse/clickhouse-js/actions/workflows/run-tests.yml">
8
- <img src="https://github.com/ClickHouse/clickhouse-js/actions/workflows/run-tests.yml/badge.svg?branch=main">
7
+ <a href="https://github.com/ClickHouse/clickhouse-js/actions/workflows/tests.yml">
8
+ <img src="https://github.com/ClickHouse/clickhouse-js/actions/workflows/tests.yml/badge.svg?branch=main">
9
+ </a>
10
+ <a href="http://htmlpreview.github.io/?https://github.com/ClickHouse/clickhouse-js/blob/main/coverage/lcov-report/index.html">
11
+ <img src="./coverage/badge.svg">
9
12
  </a>
10
13
  </p>
11
14
 
@@ -20,7 +23,7 @@ It is focused on data streaming for both inserts and selects using standard [Nod
20
23
  The client is tested with the following ClickHouse and Node.js versions:
21
24
 
22
25
  | Node.js | ClickHouse | Status |
23
- |---------|------------|--------|
26
+ | ------- | ---------- | ------ |
24
27
  | 14.x | 22.8 | ✔ |
25
28
  | 16.x | 22.8 | ✔ |
26
29
  | 18.x | 22.8 | ✔ |
@@ -147,60 +150,61 @@ See also:
147
150
 
148
151
  ## Supported formats
149
152
 
150
- | Format | Input (array) | Input (stream) | Output (JSON) | Output (text) |
151
- |--------------------------------------------|---------------|----------------|---------------|---------------|
152
- | JSON | ❌ | ❌ | ✔️ | ✔️ |
153
- | JSONEachRow | ✔️ | ✔️ | ✔️ | ✔️ |
154
- | JSONStringsEachRow | ✔️ | ✔️ | ✔️ | ✔️ |
155
- | JSONCompactEachRow | ✔️ | ✔️ | ✔️ | ✔️ |
156
- | JSONCompactStringsEachRow | ✔️ | ✔️ | ✔️ | ✔️ |
157
- | JSONCompactEachRowWithNames | ✔️ | ✔️ | ✔️ | ✔️ |
158
- | JSONCompactEachRowWithNamesAndTypes | ✔️ | ✔️ | ✔️ | ✔️ |
159
- | JSONCompactStringsEachRowWithNames | ✔️ | ✔️ | ✔️ | ✔️ |
160
- | JSONCompactStringsEachRowWithNamesAndTypes | ✔️ | ✔️ | ✔️ | ✔️ |
161
- | CSV | | ✔️ | | ✔️ |
162
- | CSVWithNames | ❌ | ✔️ | ❌ | ✔️ |
163
- | CSVWithNamesAndTypes | ❌ | ✔️ | ❌ | ✔️ |
164
- | TabSeparated | ❌ | ✔️ | ❌ | ✔️ |
165
- | TabSeparatedRaw | ❌ | ✔️ | ❌ | ✔️ |
166
- | TabSeparatedWithNames | ❌ | ✔️ | ❌ | ✔️ |
167
- | TabSeparatedWithNamesAndTypes | ❌ | ✔️ | ❌ | ✔️ |
168
- | CustomSeparated | ❌ | ✔️ | ❌ | ✔️ |
169
- | CustomSeparatedWithNames | ❌ | ✔️ | ❌ | ✔️ |
170
- | CustomSeparatedWithNamesAndTypes | ❌ | ✔️ | ❌ | ✔️ |
153
+ | Format | Input (array) | Input (stream) | Input (object) | Output (JSON) | Output (text) |
154
+ | ------------------------------------------ | ------------- | -------------- | -------------- | ------------- | ------------- |
155
+ | JSON | ❌ | ❌ | ✔️ | ✔️ | ✔️ |
156
+ | JSONObjectEachRow | | ❌ | ✔️ | ✔️ | ✔️ |
157
+ | JSONEachRow | ✔️ | ✔️ | ❌️ | ✔️ | ✔️ |
158
+ | JSONStringsEachRow | ✔️ | ✔️ | ❌️ | ✔️ | ✔️ |
159
+ | JSONCompactEachRow | ✔️ | ✔️ | ❌️ | ✔️ | ✔️ |
160
+ | JSONCompactStringsEachRow | ✔️ | ✔️ | ❌️ | ✔️ | ✔️ |
161
+ | JSONCompactEachRowWithNames | ✔️ | ✔️ | ❌️ | ✔️ | ✔️ |
162
+ | JSONCompactEachRowWithNamesAndTypes | ✔️ | ✔️ | ❌️ | ✔️ | ✔️ |
163
+ | JSONCompactStringsEachRowWithNames | ✔️ | ✔️ | ❌️ | ✔️ | ✔️ |
164
+ | JSONCompactStringsEachRowWithNamesAndTypes | ✔️ | ✔️ | ❌️ | ✔️ | ✔️ |
165
+ | CSV | ❌ | ✔️ | ❌ | ❌ | ✔️ |
166
+ | CSVWithNames | ❌ | ✔️ | ❌ | ❌ | ✔️ |
167
+ | CSVWithNamesAndTypes | ❌ | ✔️ | ❌ | ❌ | ✔️ |
168
+ | TabSeparated | ❌ | ✔️ | ❌ | ❌ | ✔️ |
169
+ | TabSeparatedRaw | ❌ | ✔️ | ❌ | ❌ | ✔️ |
170
+ | TabSeparatedWithNames | ❌ | ✔️ | ❌ | ❌ | ✔️ |
171
+ | TabSeparatedWithNamesAndTypes | ❌ | ✔️ | ❌ | ❌ | ✔️ |
172
+ | CustomSeparated | ❌ | ✔️ | ❌ | ❌ | ✔️ |
173
+ | CustomSeparatedWithNames | ❌ | ✔️ | ❌ | ❌ | ✔️ |
174
+ | CustomSeparatedWithNamesAndTypes | ❌ | ✔️ | ❌ | ❌ | ✔️ |
171
175
 
172
176
  The entire list of ClickHouse input and output formats is available [here](https://clickhouse.com/docs/en/interfaces/formats).
173
177
 
174
178
  ## Supported ClickHouse data types
175
179
 
176
- | Type | Status | JS type |
177
- |----------------|----------------|---------------------------------------|
178
- | UInt8/16/32 | ✔️ | number |
180
+ | Type | Status | JS type |
181
+ | -------------- | --------------- | ------------------------------------- |
182
+ | UInt8/16/32 | ✔️ | number |
179
183
  | UInt64/128/256 | ✔️❗- see below | string |
180
- | Int8/16/32 | ✔️ | number |
184
+ | Int8/16/32 | ✔️ | number |
181
185
  | Int64/128/256 | ✔️❗- see below | string |
182
- | Float32/64 | ✔️ | number |
186
+ | Float32/64 | ✔️ | number |
183
187
  | Decimal | ✔️❗- see below | number |
184
- | Boolean | ✔️ | boolean |
185
- | String | ✔️ | string |
186
- | FixedString | ✔️ | string |
187
- | UUID | ✔️ | string |
188
+ | Boolean | ✔️ | boolean |
189
+ | String | ✔️ | string |
190
+ | FixedString | ✔️ | string |
191
+ | UUID | ✔️ | string |
188
192
  | Date32/64 | ✔️❗- see below | string |
189
193
  | DateTime32/64 | ✔️❗- see below | string |
190
- | Enum | ✔️ | string |
191
- | LowCardinality | ✔️ | string |
192
- | Array(T) | ✔️ | Array\<JS type for T> |
193
- | JSON | ✔️ | object |
194
+ | Enum | ✔️ | string |
195
+ | LowCardinality | ✔️ | string |
196
+ | Array(T) | ✔️ | Array\<JS type for T> |
197
+ | JSON | ✔️ | object |
194
198
  | Nested | ❌ | - |
195
- | Tuple | ✔️ | Tuple |
196
- | Nullable(T) | ✔️ | JS type for T or null |
197
- | IPv4 | ✔️ | string |
198
- | IPv6 | ✔️ | string |
199
- | Point | ✔️ | [ number, number ] |
200
- | Ring | ✔️ | Array\<Point> |
201
- | Polygon | ✔️ | Array\<Ring> |
202
- | MultiPolygon | ✔️ | Array\<Polygon> |
203
- | Map(K, V) | ✔️ | Record\<JS type for K, JS type for V> |
199
+ | Tuple | ✔️ | Tuple |
200
+ | Nullable(T) | ✔️ | JS type for T or null |
201
+ | IPv4 | ✔️ | string |
202
+ | IPv6 | ✔️ | string |
203
+ | Point | ✔️ | [ number, number ] |
204
+ | Ring | ✔️ | Array\<Point> |
205
+ | Polygon | ✔️ | Array\<Ring> |
206
+ | MultiPolygon | ✔️ | Array\<Polygon> |
207
+ | Map(K, V) | ✔️ | Record\<JS type for K, JS type for V> |
204
208
 
205
209
  The entire list of supported ClickHouse formats is available [here](https://clickhouse.com/docs/en/sql-reference/data-types/).
206
210
 
@@ -251,12 +255,12 @@ class ClickHouseClient {
251
255
  }
252
256
  ```
253
257
 
254
- #### Rows response abstraction
258
+ #### ResultSet response abstraction
255
259
 
256
- Provides several convenience methods for data processing in your application.
260
+ Provides several convenience methods for data processing of select results in your application.
257
261
 
258
262
  ```ts
259
- class Rows {
263
+ class ResultSet {
260
264
  // Consume the entire stream and get the contents as a string
261
265
  // Can be used with any DataFormat
262
266
  // Should be called only once
@@ -265,17 +269,18 @@ class Rows {
265
269
  // Can be used only with JSON formats
266
270
  // Should be called only once
267
271
  json<T>(): Promise<T> {}
268
- // Returns a readable stream of Row instances for responses that can be streamed (i.e. all except JSON)
272
+ // Returns a readable stream for responses that can be streamed (i.e. all except JSON)
273
+ // Every iteration provides an array of `Row` instances
269
274
  // Should be called only once
270
275
  // NB: if called for the second time, the second stream will be just empty
271
276
  stream(): Stream.Readable {}
272
277
  }
273
278
 
274
- class Row {
275
- // Get the content of the row as plain string
276
- text(): string {}
277
- // Get the content of the row as a JS object
278
- json<T>(): T {}
279
+ interface Row {
280
+ // Get the content of an individual row as a plain string
281
+ text(): string
282
+ // Get the content of an individual row as a JS object
283
+ json<T>(): T
279
284
  }
280
285
  ```
281
286
 
@@ -365,265 +370,12 @@ class ClickHouseClient {
365
370
 
366
371
  ## Usage examples
367
372
 
368
- ### Create a table (single node)
369
-
370
- ```ts
371
- await client.exec({
372
- query: `
373
- CREATE TABLE foobar
374
- (id UInt64, name String)
375
- ENGINE MergeTree()
376
- ORDER BY (id)
377
- `,
378
- })
379
- ```
380
-
381
- ### Create a table (local cluster)
382
-
383
- ```ts
384
- await client.exec({
385
- query: `
386
- CREATE TABLE foobar ON CLUSTER '{cluster}'
387
- (id UInt64, name String)
388
- ENGINE ReplicatedMergeTree(
389
- '/clickhouse/{cluster}/tables/{database}/{table}/{shard}',
390
- '{replica}'
391
- )
392
- ORDER BY (id)
393
- `,
394
- // Recommended for cluster usage to avoid situations
395
- // where a query processing error occurred after the response code
396
- // and HTTP headers were sent to the client.
397
- // See https://clickhouse.com/docs/en/interfaces/http/#response-buffering
398
- clickhouse_settings: {
399
- wait_end_of_query: 1,
400
- },
401
- })
402
- ```
403
-
404
- ### Create a table (ClickHouse cloud)
405
-
406
- Note that `ENGINE` and `ON CLUSTER` clauses can be omitted entirely here.
407
-
408
- ClickHouse cloud will automatically use `ReplicatedMergeTree` with appropriate settings in this case.
409
-
410
- ```ts
411
- await client.exec({
412
- query: `
413
- CREATE TABLE foobar
414
- (id UInt64, name String)
415
- ORDER BY (id)
416
- `,
417
- // Recommended for cluster usage to avoid situations
418
- // where a query processing error occurred after the response code
419
- // and HTTP headers were sent to the client.
420
- // See https://clickhouse.com/docs/en/interfaces/http/#response-buffering
421
- clickhouse_settings: {
422
- wait_end_of_query: 1,
423
- },
424
- })
425
- ```
426
-
427
- ### Insert with array input (JSON\* family formats only)
428
-
429
- ```ts
430
- await client.insert({
431
- table: tableName,
432
- // structure should match the desired format, JSONEachRow in this example
433
- values: [
434
- { id: 42, name: 'foo' },
435
- { id: 42, name: 'bar' },
436
- ],
437
- format: 'JSONEachRow',
438
- })
439
- ```
440
-
441
- ### Insert with stream input (any format except JSON, stream is created out of an array)
442
-
443
- ```ts
444
- await client.insert({
445
- table: tableName,
446
- // structure should match the desired format, JSONCompactEachRow in this example
447
- values: Stream.Readable.from([
448
- [42, 'foo'],
449
- [42, 'bar'],
450
- ]),
451
- format: 'JSONCompactEachRow',
452
- })
453
- ```
454
-
455
- ### Insert with stream input (any format except JSON, flowing stream)
456
-
457
- ```ts
458
- const stream = new Stream.Readable({
459
- objectMode: true, // required for JSON* family formats
460
- read() {
461
- /* stub */
462
- },
463
- })
464
- // ... your (async) code pushing the values into the stream...
465
- await client.insert({
466
- table: tableName,
467
- values: stream,
468
- format: 'JSONEachRow', // or any other desired JSON* format
469
- })
470
- // close the stream when finished by pushing a null value there
471
- stream.push(null)
472
- ```
473
-
474
- ### Insert with stream input ("raw" formats like CSV* / TabSeparated* / CustomSeparated\*, stream is created out of an array)
475
-
476
- ```ts
477
- await client.insert({
478
- table: tableName,
479
- // structure should match the desired format, TabSeparated in this example
480
- values: Stream.Readable.from(['42,foobar'], {
481
- objectMode: false, // required for "raw" family formats
482
- }),
483
- format: 'TabSeparated', // or any other desired "raw" format
484
- })
485
- ```
486
-
487
- ### Insert with stream input ("raw" formats like CSV* / TabSeparated* / CustomSeparated\*, flowing stream)
488
-
489
- ```ts
490
- const stream = new Stream.Readable({
491
- objectMode: false, // required for "raw" family formats
492
- read() {
493
- /* stub */
494
- },
495
- })
496
- // ... your (async) code pushing the values into the stream...
497
- await client.insert({
498
- table: tableName,
499
- values: stream,
500
- format: 'TabSeparated', // or any other desired "raw" format
501
- })
502
- // close the stream when finished by pushing a null value there
503
- stream.push(null)
504
- ```
505
-
506
- ### Inserting a file (for example, CSV)
507
-
508
- ```ts
509
- const filename = Path.resolve(process.cwd(), 'path/to/file.csv')
510
- await client.insert({
511
- table: tableName,
512
- values: Fs.createReadStream(filename),
513
- format: 'CSVWithNames',
514
- })
515
- ```
373
+ You can find code samples in the [examples](./examples) folder (with [README](./examples/README.md)).
516
374
 
517
375
  See also:
518
376
 
519
- - [NDJSON file streaming example](https://github.com/ClickHouse/clickhouse-js/blob/60c484a3492420baed4b4c6c33cc0845262285e7/examples/streaming/stream_ndjson.ts)
520
377
  - [Memory leaks test using Brown University benchmarks files](https://github.com/ClickHouse/clickhouse-js/blob/60c484a3492420baed4b4c6c33cc0845262285e7/benchmarks/leaks/memory_leak_brown.ts#L72-L80)
521
378
 
522
- ### Selecting the data as JSON using a JSON\* family format
523
-
524
- ```ts
525
- const rows = await client.query({
526
- query: 'SELECT number FROM system.numbers LIMIT 5',
527
- format: 'JSONCompactEachRow',
528
- })
529
- const result = await rows.json()
530
- // result is [['0'], ['1'], ['2'], ['3'], ['4']]
531
- ```
532
-
533
- ### Selecting the data as JSON including response metadata
534
-
535
- ```ts
536
- const rows = await client.query({
537
- query: 'SELECT number FROM system.numbers LIMIT 2',
538
- format: 'JSON',
539
- })
540
- const result = await rows.json<ResponseJSON<{ number: string }>>()
541
-
542
- /* result will look like
543
-
544
- {
545
- "meta": [ { "name": "number", "type": "UInt64" } ],
546
- "data": [ { "number": "0"}, { "number": "1" } ],
547
- "rows": 2,
548
- "rows_before_limit_at_least": 2,
549
- "statistics": {
550
- "elapsed": 0.00013129,
551
- "rows_read": 2,
552
- "bytes_read": 16
553
- }
554
- }
555
-
556
- */
557
- ```
558
-
559
- ### Selecting the data as text
560
-
561
- ```ts
562
- const rows = await client.query({
563
- query: `SELECT number FROM system.numbers LIMIT 2`,
564
- format: 'CSV',
565
- })
566
- const result = await rows.text()
567
- // result is now '0\n1\n'
568
- ```
569
-
570
- ### Selecting the data as a stream
571
-
572
- ```ts
573
- const rows = await client.query({
574
- query: `SELECT * from ${tableName}`,
575
- format: 'JSONCompactEachRow',
576
- })
577
- for await (const row of rows.stream()) {
578
- const data = (row as Row).json()
579
- // ... your code processing the data here
580
- }
581
- ```
582
-
583
- ### Query with parameter binding
584
-
585
- ```ts
586
- const rows = await client.query({
587
- query: 'SELECT plus({val1: Int32}, {val2: Int32})',
588
- format: 'CSV',
589
- query_params: {
590
- val1: 10,
591
- val2: 20,
592
- },
593
- })
594
- const result = await rows.text()
595
- // result is '30\n'
596
- ```
597
-
598
- ### Query with custom ClickHouse settings
599
-
600
- ```ts
601
- await client.insert({
602
- table: tableName,
603
- values: [
604
- { id: 42, name: 'foo' },
605
- { id: 42, name: 'bar' },
606
- ],
607
- format: 'JSONEachRow',
608
- clickhouse_settings: { insert_quorum: '2' },
609
- })
610
- ```
611
-
612
- ### Abort query
613
-
614
- ```ts
615
- import { AbortController } from 'node-abort-controller'
616
-
617
- const controller = new AbortController()
618
- const selectPromise = client.query({
619
- query: 'SELECT sleep(3)',
620
- format: 'CSV',
621
- abort_signal: controller.signal as AbortSignal,
622
- })
623
- controller.abort()
624
- // selectPromise is now rejected with "The request was aborted" message
625
- ```
626
-
627
379
  ## Known limitations
628
380
 
629
381
  - Browser usage is not supported.
@@ -1,4 +1,3 @@
1
- export declare type DataType = 'UInt8' | 'UInt16' | 'UInt32' | 'UInt64' | 'UInt128' | 'UInt256' | 'Int8' | 'Int16' | 'Int32' | 'Int64' | 'Int128' | 'Int256' | 'Float32' | 'Float64';
2
1
  export interface ResponseJSON<T = unknown> {
3
2
  data: Array<T>;
4
3
  query_id?: string;
@@ -6,7 +5,7 @@ export interface ResponseJSON<T = unknown> {
6
5
  extremes?: Record<string, any>;
7
6
  meta?: Array<{
8
7
  name: string;
9
- type: DataType;
8
+ type: string;
10
9
  }>;
11
10
  statistics?: {
12
11
  elapsed: number;
@@ -15,3 +14,11 @@ export interface ResponseJSON<T = unknown> {
15
14
  };
16
15
  rows?: number;
17
16
  }
17
+ export interface InputJSON<T = unknown> {
18
+ meta: {
19
+ name: string;
20
+ type: string;
21
+ }[];
22
+ data: T[];
23
+ }
24
+ export declare type InputJSONObjectEachRow<T = unknown> = Record<string, T>;
package/dist/client.d.ts CHANGED
@@ -2,42 +2,66 @@
2
2
  import Stream from 'stream';
3
3
  import { Logger } from './logger';
4
4
  import { type DataFormat } from './data_formatter';
5
- import { Rows } from './rows';
5
+ import { ResultSet } from './result';
6
6
  import type { ClickHouseSettings } from './settings';
7
+ import type { InputJSON, InputJSONObjectEachRow } from './clickhouse_types';
7
8
  export interface ClickHouseClientConfigOptions {
9
+ /** A ClickHouse instance URL. Default value: `http://localhost:8123`. */
8
10
  host?: string;
11
+ /** The timeout to set up a connection in milliseconds. Default value: `10_000`. */
9
12
  connect_timeout?: number;
13
+ /** The request timeout in milliseconds. Default value: `30_000`. */
10
14
  request_timeout?: number;
15
+ /** Maximum number of sockets to allow per host. Default value: `Infinity`. */
11
16
  max_open_connections?: number;
12
17
  compression?: {
18
+ /** `response: true` instructs ClickHouse server to respond with compressed response body. Default: true. */
13
19
  response?: boolean;
20
+ /** `request: true` enabled compression on the client request body. Default: false. */
14
21
  request?: boolean;
15
22
  };
23
+ /** The name of the user on whose behalf requests are made. Default: 'default'. */
16
24
  username?: string;
25
+ /** The user password. Default: ''. */
17
26
  password?: string;
27
+ /** The name of the application using the nodejs client. Default: 'clickhouse-js'. */
18
28
  application?: string;
29
+ /** Database name to use. Default value: `default`. */
19
30
  database?: string;
31
+ /** ClickHouse settings to apply to all requests. Default value: {} */
20
32
  clickhouse_settings?: ClickHouseSettings;
21
33
  log?: {
34
+ /** Enable logging. Default value: false. */
22
35
  enable?: boolean;
36
+ /** A class to instantiate a custom logger implementation. */
23
37
  LoggerClass?: new (enabled: boolean) => Logger;
24
38
  };
25
39
  }
26
40
  export interface BaseParams {
41
+ /** ClickHouse settings that can be applied on query level. */
27
42
  clickhouse_settings?: ClickHouseSettings;
43
+ /** Parameters for query binding. https://clickhouse.com/docs/en/interfaces/http/#cli-queries-with-parameters */
28
44
  query_params?: Record<string, unknown>;
45
+ /** AbortSignal instance (using `node-abort-controller` package) to cancel a request in progress. */
29
46
  abort_signal?: AbortSignal;
30
47
  }
31
48
  export interface QueryParams extends BaseParams {
49
+ /** Statement to execute. */
32
50
  query: string;
51
+ /** Format of the resulting dataset. */
33
52
  format?: DataFormat;
34
53
  }
35
54
  export interface ExecParams extends BaseParams {
55
+ /** Statement to execute. */
36
56
  query: string;
37
57
  }
58
+ declare type InsertValues<T> = ReadonlyArray<T> | Stream.Readable | InputJSON<T> | InputJSONObjectEachRow<T>;
38
59
  export interface InsertParams<T = unknown> extends BaseParams {
60
+ /** Name of a table to insert into. */
39
61
  table: string;
40
- values: ReadonlyArray<T> | Stream.Readable;
62
+ /** A dataset to insert. */
63
+ values: InsertValues<T>;
64
+ /** Format of the dataset to insert. */
41
65
  format?: DataFormat;
42
66
  }
43
67
  export declare class ClickHouseClient {
@@ -46,11 +70,22 @@ export declare class ClickHouseClient {
46
70
  readonly logger: Logger;
47
71
  constructor(config?: ClickHouseClientConfigOptions);
48
72
  private getBaseParams;
49
- query(params: QueryParams): Promise<Rows>;
73
+ query(params: QueryParams): Promise<ResultSet>;
50
74
  exec(params: ExecParams): Promise<Stream.Readable>;
51
75
  insert<T>(params: InsertParams<T>): Promise<void>;
52
76
  ping(): Promise<boolean>;
53
77
  close(): Promise<void>;
54
78
  }
55
- export declare function validateInsertValues(values: ReadonlyArray<any> | Stream.Readable, format: DataFormat): void;
79
+ export declare function validateInsertValues<T>(values: InsertValues<T>, format: DataFormat): void;
80
+ /**
81
+ * A function encodes an array or a stream of JSON objects to a format compatible with ClickHouse.
82
+ * If values are provided as an array of JSON objects, the function encodes it in place.
83
+ * If values are provided as a stream of JSON objects, the function sets up the encoding of each chunk.
84
+ * If values are provided as a raw non-object stream, the function does nothing.
85
+ *
86
+ * @param values a set of values to send to ClickHouse.
87
+ * @param format a format to encode value to.
88
+ */
89
+ export declare function encodeValues<T>(values: InsertValues<T>, format: DataFormat): string | Stream.Readable;
56
90
  export declare function createClient(config?: ClickHouseClientConfigOptions): ClickHouseClient;
91
+ export {};
package/dist/client.js CHANGED
@@ -3,13 +3,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.createClient = exports.validateInsertValues = exports.ClickHouseClient = void 0;
6
+ exports.createClient = exports.encodeValues = exports.validateInsertValues = exports.ClickHouseClient = void 0;
7
7
  const stream_1 = __importDefault(require("stream"));
8
8
  const connection_1 = require("./connection");
9
9
  const logger_1 = require("./logger");
10
10
  const utils_1 = require("./utils");
11
11
  const data_formatter_1 = require("./data_formatter");
12
- const rows_1 = require("./rows");
12
+ const result_1 = require("./result");
13
13
  function validateConfig({ url }) {
14
14
  if (url.protocol !== 'http:' && url.protocol !== 'https:') {
15
15
  throw new Error(`Only http(s) protocol is supported, but given: [${url.protocol}]`);
@@ -88,15 +88,15 @@ class ClickHouseClient {
88
88
  var _a;
89
89
  const format = (_a = params.format) !== null && _a !== void 0 ? _a : 'JSON';
90
90
  const query = formatQuery(params.query, format);
91
- const stream = await this.connection.select({
91
+ const stream = await this.connection.query({
92
92
  query,
93
93
  ...this.getBaseParams(params),
94
94
  });
95
- return new rows_1.Rows(stream, format);
95
+ return new result_1.ResultSet(stream, format);
96
96
  }
97
97
  exec(params) {
98
98
  const query = removeSemi(params.query.trim());
99
- return this.connection.command({
99
+ return this.connection.exec({
100
100
  query,
101
101
  ...this.getBaseParams(params),
102
102
  });
@@ -132,8 +132,11 @@ function removeSemi(query) {
132
132
  return query;
133
133
  }
134
134
  function validateInsertValues(values, format) {
135
- if (Array.isArray(values) === false && (0, utils_1.isStream)(values) === false) {
136
- throw new Error('Insert expected "values" to be an array or a stream of values.');
135
+ if (!Array.isArray(values) &&
136
+ !(0, utils_1.isStream)(values) &&
137
+ typeof values !== 'object') {
138
+ throw new Error('Insert expected "values" to be an array, a stream of values or a JSON object, ' +
139
+ `got: ${typeof values}`);
137
140
  }
138
141
  if ((0, utils_1.isStream)(values)) {
139
142
  if ((0, data_formatter_1.isSupportedRawFormat)(format)) {
@@ -166,8 +169,16 @@ function encodeValues(values, format) {
166
169
  return stream_1.default.pipeline(values, (0, utils_1.mapStream)((value) => (0, data_formatter_1.encodeJSON)(value, format)), pipelineCb);
167
170
  }
168
171
  // JSON* arrays
169
- return values.map((value) => (0, data_formatter_1.encodeJSON)(value, format)).join('');
172
+ if (Array.isArray(values)) {
173
+ return values.map((value) => (0, data_formatter_1.encodeJSON)(value, format)).join('');
174
+ }
175
+ // JSON & JSONObjectEachRow format input
176
+ if (typeof values === 'object') {
177
+ return (0, data_formatter_1.encodeJSON)(values, format);
178
+ }
179
+ throw new Error(`Cannot encode values of type ${typeof values} with ${format} format`);
170
180
  }
181
+ exports.encodeValues = encodeValues;
171
182
  function createClient(config) {
172
183
  return new ClickHouseClient(config);
173
184
  }
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA2B;AAC3B,6CAAgE;AAChE,qCAAiC;AACjC,mCAA6C;AAC7C,qDAIyB;AACzB,iCAA6B;AAgD7B,SAAS,cAAc,CAAC,EAAE,GAAG,EAAoB;IAC/C,IAAI,GAAG,CAAC,QAAQ,KAAK,OAAO,IAAI,GAAG,CAAC,QAAQ,KAAK,QAAQ,EAAE;QACzD,MAAM,IAAI,KAAK,CACb,mDAAmD,GAAG,CAAC,QAAQ,GAAG,CACnE,CAAA;KACF;IACD,0BAA0B;AAC5B,CAAC;AAED,SAAS,SAAS,CAAC,IAAY;IAC7B,IAAI;QACF,OAAO,IAAI,GAAG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;IAElB,IAAI,IAAA,gBAAQ,EAAC,MAAM,CAAC,EAAE;QACpB,yEAAyE;QACzE,IAAI,CAAC,MAAM,CAAC,kBAAkB,EAAE;YAC9B,OAAO,MAAM,CAAA;SACd;QACD,wBAAwB;QACxB,OAAO,gBAAM,CAAC,QAAQ,CACpB,MAAM,EACN,IAAA,iBAAS,EAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,2BAAU,EAAC,KAAK,EAAE,MAAM,CAAC,CAAC,EAC/C,UAAU,CACX,CAAA;KACF;IACD,eAAe;IACf,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QACzB,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,2BAAU,EAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;KACjE;IACD,wCAAwC;IACxC,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;QAC9B,OAAO,IAAA,2BAAU,EAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KAClC;IACD,MAAM,IAAI,KAAK,CACb,gCAAgC,OAAO,MAAM,SAAS,MAAM,SAAS,CACtE,CAAA;AACH,CAAC;AA3BD,oCA2BC;AAED,SAAgB,YAAY,CAC1B,MAAsC;IAEtC,OAAO,IAAI,gBAAgB,CAAC,MAAM,CAAC,CAAA;AACrC,CAAC;AAJD,oCAIC;AAED,SAAS,UAAU,CAAC,GAAiC;IACnD,IAAI,GAAG,EAAE;QACP,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;KACnB;AACH,CAAC"}
@@ -21,8 +21,8 @@ export declare abstract class BaseHttpAdapter implements Connection {
21
21
  protected abstract createClientRequest(url: URL, params: RequestParams): Http.ClientRequest;
22
22
  protected request(params: RequestParams): Promise<Stream.Readable>;
23
23
  ping(): Promise<boolean>;
24
- select(params: BaseParams): Promise<Stream.Readable>;
25
- command(params: BaseParams): Promise<Stream.Readable>;
24
+ query(params: BaseParams): Promise<Stream.Readable>;
25
+ exec(params: BaseParams): Promise<Stream.Readable>;
26
26
  insert(params: InsertParams): Promise<void>;
27
27
  close(): Promise<void>;
28
28
  private logResponse;
@@ -193,7 +193,7 @@ class BaseHttpAdapter {
193
193
  response.destroy();
194
194
  return true;
195
195
  }
196
- async select(params) {
196
+ async query(params) {
197
197
  const clickhouse_settings = withHttpSettings(params.clickhouse_settings, this.config.compression.decompress_response);
198
198
  const searchParams = (0, http_search_params_1.toSearchParams)({
199
199
  database: this.config.database,
@@ -208,7 +208,7 @@ class BaseHttpAdapter {
208
208
  decompress_response: clickhouse_settings.enable_http_compression === 1,
209
209
  });
210
210
  }
211
- async command(params) {
211
+ async exec(params) {
212
212
  const searchParams = (0, http_search_params_1.toSearchParams)({
213
213
  database: this.config.database,
214
214
  clickhouse_settings: params.clickhouse_settings,
@@ -1 +1 @@
1
- {"version":3,"file":"base_http_adapter.js","sourceRoot":"","sources":["../../../src/connection/adapter/base_http_adapter.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA2B;AAE3B,gDAAuB;AACvB,uCAAwC;AAUxC,6DAAqD;AACrD,mDAA8C;AAC9C,uCAAiD;AAYjD,SAAS,oBAAoB,CAAC,UAAmB;IAC/C,OAAO,OAAO,CAAC,UAAU,IAAI,GAAG,IAAI,UAAU,IAAI,UAAU,GAAG,GAAG,CAAC,CAAA;AACrE,CAAC;AAED,SAAS,aAAa,CAAC,MAAW;IAChC,OAAO,qBAAqB,IAAI,MAAM,CAAA;AACxC,CAAC;AAED,SAAS,gBAAgB,CACvB,mBAAwC,EACxC,WAAqB;IAErB,OAAO;QACL,GAAG,CAAC,WAAW;YACb,CAAC,CAAC;gBACE,uBAAuB,EAAE,CAAC;aAC3B;YACH,CAAC,CAAC,EAAE,CAAC;QACP,GAAG,mBAAmB;KACvB,CAAA;AACH,CAAC;AAED,SAAS,mBAAmB,CAC1B,QAAgB,EAChB,QAAgB;IAEhB,OAAO;QACL,aAAa,EA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,GAAG,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC,CAAC,EAAE,iBAAiB,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACpE,GAAG,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,kBAAkB,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACnE,CAAA;IACH,CAAC;CACF;AAhOD,0CAgOC"}
1
+ {"version":3,"file":"base_http_adapter.js","sourceRoot":"","sources":["../../../src/connection/adapter/base_http_adapter.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA2B;AAE3B,gDAAuB;AACvB,uCAAwC;AAUxC,6DAAqD;AACrD,mDAA8C;AAC9C,uCAAiD;AAYjD,SAAS,oBAAoB,CAAC,UAAmB;IAC/C,OAAO,OAAO,CAAC,UAAU,IAAI,GAAG,IAAI,UAAU,IAAI,UAAU,GAAG,GAAG,CAAC,CAAA;AACrE,CAAC;AAED,SAAS,aAAa,CAAC,MAAW;IAChC,OAAO,qBAAqB,IAAI,MAAM,CAAA;AACxC,CAAC;AAED,SAAS,gBAAgB,CACvB,mBAAwC,EACxC,WAAqB;IAErB,OAAO;QACL,GAAG,CAAC,WAAW;YACb,CAAC,CAAC;gBACE,uBAAuB,EAAE,CAAC;aAC3B;YACH,CAAC,CAAC,EAAE,CAAC;QACP,GAAG,mBAAmB;KACvB,CAAA;AACH,CAAC;AAED,SAAS,mBAAmB,CAC1B,QAAgB,EAChB,QAAgB;IAEhB,OAAO;QACL,aAAa,EAAE,SAAS,MAAM,CAAC,IAAI,CAAC,GAAG,QAAQ,IAAI,QAAQ,EAAE,CAAC,CAAC,QAAQ,CACrE,QAAQ,CACT,EAAE;KACJ,CAAA;AACH,CAAC;AAED,SAAS,kBAAkB,CAAC,QAA8B;IAKxD,MAAM,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAA;IAErD,IAAI,QAAQ,KAAK,MAAM,EAAE;Q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"}
@@ -27,8 +27,8 @@ export interface InsertParams extends BaseParams {
27
27
  export interface Connection {
28
28
  ping(): Promise<boolean>;
29
29
  close(): Promise<void>;
30
- select(params: BaseParams): Promise<Stream.Readable>;
31
- command(params: BaseParams): Promise<Stream.Readable>;
30
+ query(params: BaseParams): Promise<Stream.Readable>;
31
+ exec(params: BaseParams): Promise<Stream.Readable>;
32
32
  insert(params: InsertParams): Promise<void>;
33
33
  }
34
34
  export declare function createConnection(params: ConnectionParams, logger: Logger): Connection;
@@ -1,4 +1,4 @@
1
- declare const supportedJSONFormats: readonly ["JSON", "JSONEachRow", "JSONStringsEachRow", "JSONCompactEachRow", "JSONCompactStringsEachRow", "JSONCompactEachRowWithNames", "JSONCompactEachRowWithNamesAndTypes", "JSONCompactStringsEachRowWithNames", "JSONCompactStringsEachRowWithNamesAndTypes"];
1
+ declare const supportedJSONFormats: readonly ["JSON", "JSONObjectEachRow", "JSONEachRow", "JSONStringsEachRow", "JSONCompactEachRow", "JSONCompactStringsEachRow", "JSONCompactEachRowWithNames", "JSONCompactEachRowWithNamesAndTypes", "JSONCompactStringsEachRowWithNames", "JSONCompactStringsEachRowWithNamesAndTypes"];
2
2
  declare const supportedRawFormats: readonly ["CSV", "CSVWithNames", "CSVWithNamesAndTypes", "TabSeparated", "TabSeparatedRaw", "TabSeparatedWithNames", "TabSeparatedWithNamesAndTypes", "CustomSeparated", "CustomSeparatedWithNames", "CustomSeparatedWithNamesAndTypes"];
3
3
  export declare type JSONDataFormat = typeof supportedJSONFormats[number];
4
4
  export declare type RawDataFormat = typeof supportedRawFormats[number];
@@ -11,7 +11,11 @@ const streamableJSONFormats = [
11
11
  'JSONCompactStringsEachRowWithNames',
12
12
  'JSONCompactStringsEachRowWithNamesAndTypes',
13
13
  ];
14
- const supportedJSONFormats = ['JSON', ...streamableJSONFormats];
14
+ const supportedJSONFormats = [
15
+ 'JSON',
16
+ 'JSONObjectEachRow',
17
+ ...streamableJSONFormats,
18
+ ];
15
19
  const supportedRawFormats = [
16
20
  'CSV',
17
21
  'CSVWithNames',
@@ -60,7 +64,7 @@ function decode(text, format) {
60
64
  .map((l) => decode(l, 'JSON'));
61
65
  }
62
66
  if (isSupportedRawFormat(format)) {
63
- throw new Error(`cannot decode ${format} to JSON`);
67
+ throw new Error(`Cannot decode ${format} to JSON`);
64
68
  }
65
69
  throw new Error(`The client does not support [${format}] format decoding.`);
66
70
  }
@@ -72,7 +76,7 @@ exports.decode = decode;
72
76
  * @returns string
73
77
  */
74
78
  function encodeJSON(value, format) {
75
- if (streamableJSONFormats.includes(format)) {
79
+ if (supportedJSONFormats.includes(format)) {
76
80
  return JSON.stringify(value) + '\n';
77
81
  }
78
82
  throw new Error(`The client does not support JSON encoding in [${format}] format.`);
@@ -1 +1 @@
1
- {"version":3,"file":"formatter.js","sourceRoot":"","sources":["../../src/data_formatter/formatter.ts"],"names":[],"mappings":";;;AAAA,MAAM,qBAAqB,GAAG;IAC5B,aAAa;IACb,oBAAoB;IACpB,oBAAoB;IACpB,2BAA2B;IAC3B,6BAA6B;IAC7B,qCAAqC;IACrC,oCAAoC;IACpC,4CAA4C;CACpC,CAAA;AACV,MAAM,oBAAoB,GAAG,CAAC,MAAM,EAAE,GAAG,qBAAqB,CAAU,CAAA;AACxE,MAAM,mBAAmB,GAAG;IAC1B,KAAK;IACL,cAAc;IACd,sBAAsB;IACtB,cAAc;IACd,iBAAiB;IACjB,uBAAuB;IACvB,+BAA+B;IAC/B,iBAAiB;IACjB,0BAA0B;IAC1B,kCAAkC;CAC1B,CAAA;AAQV,0BAA0B;AAC1B,MAAM,gBAAgB,GAAG;IACvB,GAAG,qBAAqB;IACxB,GAAG,mBAAmB;CACd,CAAA;AAGV,SAAS,sBAAsB,CAC7B,MAAkB;IAElB,mEAAmE;IACnE,OAAO,qBAAqB,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;AAC/C,CAAC;AAED,SAAgB,oBAAoB,CAAC,UAAsB;IACzD,OAAQ,mBAAyC,CAAC,QAA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CAAC,IAAI,CAAC;aACX,MAAM,CAAC,OAAO,CAAC;aACf,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAA;KACjC;IACD,IAAI,oBAAoB,CAAC,MAAM,CAAC,EAAE;QAChC,MAAM,IAAI,KAAK,CAAC,iBAAiB,MAAM,UAAU,CAAC,CAAA;KACnD;IACD,MAAM,IAAI,KAAK,CAAC,gCAAgC,MAAM,oBAAoB,CAAC,CAAA;AAC7E,CAAC;AAdD,wBAcC;AAED;;;;;GAKG;AACH,SAAgB,UAAU,CAAC,KAAU,EAAE,MAAkB;IACvD,IAAK,oBAA0C,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;QAChE,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,IAAI,CAAA;KACpC;IACD,MAAM,IAAI,KAAK,CACb,iDAAiD,MAAM,WAAW,CACnE,CAAA;AACH,CAAC;AAPD,gCAOC"}
package/dist/index.d.ts CHANGED
@@ -5,11 +5,11 @@ declare const _default: {
5
5
  };
6
6
  export default _default;
7
7
  export { type ClickHouseClientConfigOptions, type ClickHouseClient, type BaseParams, type QueryParams, type ExecParams, type InsertParams, } from './client';
8
- export { Row, Rows } from './rows';
8
+ export { Row, ResultSet } from './result';
9
9
  export type { Connection } from './connection';
10
10
  export type { DataFormat } from './data_formatter';
11
11
  export type { ClickHouseError } from './error';
12
12
  export type { Logger } from './logger';
13
- export type { ResponseJSON, DataType } from './clickhouse_types';
13
+ export type { ResponseJSON, InputJSON, InputJSONObjectEachRow, } from './clickhouse_types';
14
14
  export type { ClickHouseSettings } from './settings';
15
15
  export { SettingsMap } from './settings';
package/dist/index.js CHANGED
@@ -1,14 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SettingsMap = exports.Rows = exports.Row = exports.createClient = void 0;
3
+ exports.SettingsMap = exports.ResultSet = exports.createClient = void 0;
4
4
  const client_1 = require("./client");
5
5
  Object.defineProperty(exports, "createClient", { enumerable: true, get: function () { return client_1.createClient; } });
6
6
  exports.default = {
7
7
  createClient: client_1.createClient,
8
8
  };
9
- var rows_1 = require("./rows");
10
- Object.defineProperty(exports, "Row", { enumerable: true, get: function () { return rows_1.Row; } });
11
- Object.defineProperty(exports, "Rows", { enumerable: true, get: function () { return rows_1.Rows; } });
9
+ var result_1 = require("./result");
10
+ Object.defineProperty(exports, "ResultSet", { enumerable: true, get: function () { return result_1.ResultSet; } });
12
11
  var settings_1 = require("./settings");
13
12
  Object.defineProperty(exports, "SettingsMap", { enumerable: true, get: function () { return settings_1.SettingsMap; } });
14
13
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,qCAAuC;AAE9B,6FAFA,qBAAY,OAEA;AACrB,kBAAe;IACb,YAAY,EAAZ,qBAAY;CACb,CAAA;AAWD,+BAAkC;AAAzB,2FAAA,GAAG,OAAA;AAAE,4FAAA,IAAI,OAAA;AAQlB,uCAAwC;AAA/B,uGAAA,WAAW,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,qCAAuC;AAE9B,6FAFA,qBAAY,OAEA;AACrB,kBAAe;IACb,YAAY,EAAZ,qBAAY;CACb,CAAA;AAWD,mCAAyC;AAA3B,mGAAA,SAAS,OAAA;AAYvB,uCAAwC;AAA/B,uGAAA,WAAW,OAAA"}
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import Stream from 'stream';
3
3
  import { type DataFormat } from './data_formatter';
4
- export declare class Rows {
4
+ export declare class ResultSet {
5
5
  private _stream;
6
6
  private readonly format;
7
7
  constructor(_stream: Stream.Readable, format: DataFormat);
@@ -10,7 +10,7 @@ export declare class Rows {
10
10
  * and returns the result as a string.
11
11
  *
12
12
  * The method will throw if the underlying stream was already consumed
13
- * by calling the other methods
13
+ * by calling the other methods.
14
14
  */
15
15
  text(): Promise<string>;
16
16
  /**
@@ -18,32 +18,33 @@ export declare class Rows {
18
18
  * When the response is received in full, it will be decoded to return JSON.
19
19
  *
20
20
  * The method will throw if the underlying stream was already consumed
21
- * by calling the other methods
21
+ * by calling the other methods.
22
22
  */
23
23
  json<T>(): Promise<T>;
24
24
  /**
25
- * Returns a readable stream of {@link Row}s for responses
26
- * in {@link StreamableDataFormat} format.
25
+ * Returns a readable stream for responses that can be streamed
26
+ * (i.e. all except JSON).
27
+ *
28
+ * Every iteration provides an array of {@link Row} instances
29
+ * for {@link StreamableDataFormat} format.
30
+ *
31
+ * Should be called only once.
27
32
  *
28
33
  * The method will throw if called on a response in non-streamable format,
29
34
  * and if the underlying stream was already consumed
30
- * by calling the other methods
35
+ * by calling the other methods.
31
36
  */
32
37
  stream(): Stream.Readable;
33
38
  close(): void;
34
39
  }
35
- export declare class Row {
36
- private readonly chunk;
37
- private readonly format;
38
- constructor(chunk: string, format: DataFormat);
40
+ export interface Row {
39
41
  /**
40
- * Returns a string representation of a row.
42
+ * A string representation of a row.
41
43
  */
42
- text(): string;
44
+ text: string;
43
45
  /**
44
46
  * Returns a JSON representation of a row.
45
47
  * The method will throw if called on a response in JSON incompatible format.
46
- *
47
48
  * It is safe to call this method multiple times.
48
49
  */
49
50
  json<T>(): T;
package/dist/result.js ADDED
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.ResultSet = void 0;
27
+ const stream_1 = __importStar(require("stream"));
28
+ const utils_1 = require("./utils");
29
+ const data_formatter_1 = require("./data_formatter");
30
+ class ResultSet {
31
+ constructor(_stream, format) {
32
+ Object.defineProperty(this, "_stream", {
33
+ enumerable: true,
34
+ configurable: true,
35
+ writable: true,
36
+ value: _stream
37
+ });
38
+ Object.defineProperty(this, "format", {
39
+ enumerable: true,
40
+ configurable: true,
41
+ writable: true,
42
+ value: format
43
+ });
44
+ }
45
+ /**
46
+ * The method waits for all the rows to be fully loaded
47
+ * and returns the result as a string.
48
+ *
49
+ * The method will throw if the underlying stream was already consumed
50
+ * by calling the other methods.
51
+ */
52
+ async text() {
53
+ if (this._stream.readableEnded) {
54
+ throw Error(streamAlreadyConsumedMessage);
55
+ }
56
+ return (await (0, utils_1.getAsText)(this._stream)).toString();
57
+ }
58
+ /**
59
+ * The method waits for the all the rows to be fully loaded.
60
+ * When the response is received in full, it will be decoded to return JSON.
61
+ *
62
+ * The method will throw if the underlying stream was already consumed
63
+ * by calling the other methods.
64
+ */
65
+ async json() {
66
+ if (this._stream.readableEnded) {
67
+ throw Error(streamAlreadyConsumedMessage);
68
+ }
69
+ return (0, data_formatter_1.decode)(await this.text(), this.format);
70
+ }
71
+ /**
72
+ * Returns a readable stream for responses that can be streamed
73
+ * (i.e. all except JSON).
74
+ *
75
+ * Every iteration provides an array of {@link Row} instances
76
+ * for {@link StreamableDataFormat} format.
77
+ *
78
+ * Should be called only once.
79
+ *
80
+ * The method will throw if called on a response in non-streamable format,
81
+ * and if the underlying stream was already consumed
82
+ * by calling the other methods.
83
+ */
84
+ stream() {
85
+ // If the underlying stream has already ended by calling `text` or `json`,
86
+ // Stream.pipeline will create a new empty stream
87
+ // but without "readableEnded" flag set to true
88
+ if (this._stream.readableEnded) {
89
+ throw Error(streamAlreadyConsumedMessage);
90
+ }
91
+ (0, data_formatter_1.validateStreamFormat)(this.format);
92
+ let decodedChunk = '';
93
+ const toRows = new stream_1.Transform({
94
+ transform(chunk, encoding, callback) {
95
+ decodedChunk += chunk.toString();
96
+ const rows = [];
97
+ // eslint-disable-next-line no-constant-condition
98
+ while (true) {
99
+ const idx = decodedChunk.indexOf('\n');
100
+ if (idx !== -1) {
101
+ const text = decodedChunk.slice(0, idx);
102
+ decodedChunk = decodedChunk.slice(idx + 1);
103
+ rows.push({
104
+ text,
105
+ json() {
106
+ return (0, data_formatter_1.decode)(text, 'JSON');
107
+ },
108
+ });
109
+ }
110
+ else {
111
+ if (rows.length) {
112
+ this.push(rows);
113
+ }
114
+ break;
115
+ }
116
+ }
117
+ callback();
118
+ },
119
+ autoDestroy: true,
120
+ objectMode: true,
121
+ });
122
+ return stream_1.default.pipeline(this._stream, toRows, function pipelineCb(err) {
123
+ if (err) {
124
+ console.error(err);
125
+ }
126
+ });
127
+ }
128
+ close() {
129
+ this._stream.destroy();
130
+ }
131
+ }
132
+ exports.ResultSet = ResultSet;
133
+ const streamAlreadyConsumedMessage = 'Stream has been already consumed';
134
+ //# sourceMappingURL=result.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"result.js","sourceRoot":"","sources":["../src/result.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,iDAA0C;AAE1C,mCAAmC;AACnC,qDAAgF;AAEhF,MAAa,SAAS;IACpB,YACU,OAAwB,EACf,MAAkB;;;;;mBAD3B;;;;;;mBACS;;IACh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AAC,GAAG,GAAG,CAAC,CAAC,CAAA;wBAC1C,IAAI,CAAC,IAAI,CAAC;4BACR,IAAI;4BACJ,IAAI;gCACF,OAAO,IAAA,uBAAM,EAAC,IAAI,EAAE,MAAM,CAAC,CAAA;4BAC7B,CAAC;yBACF,CAAC,CAAA;qBACH;yBAAM;wBACL,IAAI,IAAI,CAAC,MAAM,EAAE;4BACf,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;yBAChB;wBACD,MAAK;qBACN;iBACF;gBACD,QAAQ,EAAE,CAAA;YACZ,CAAC;YACD,WAAW,EAAE,IAAI;YACjB,UAAU,EAAE,IAAI;SACjB,CAAC,CAAA;QAEF,OAAO,gBAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,UAAU,CAAC,GAAG;YAClE,IAAI,GAAG,EAAE;gBACP,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;aACnB;QACH,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,KAAK;QACH,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAA;IACxB,CAAC;CACF;AArGD,8BAqGC;AAgBD,MAAM,4BAA4B,GAAG,kCAAkC,CAAA"}
@@ -3,7 +3,7 @@ import type { CreateTableOptions, TableOptions } from './index';
3
3
  import type { WhereExpr } from './where';
4
4
  import type { NonEmptyArray } from './common';
5
5
  export declare const QueryFormatter: {
6
- createTable: <S extends Shape>(tableOptions: TableOptions<S>, { engine, if_not_exists, on_cluster, order_by, partition_by, primary_key, settings, }: CreateTableOptions<S>) => string;
6
+ createTable: <S extends Shape>(tableOptions: TableOptions<S>, { engine: _engine, if_not_exists, on_cluster, order_by, partition_by, primary_key, settings: _settings, }: CreateTableOptions<S>) => string;
7
7
  select: <S_1 extends Shape>(tableOptions: TableOptions<S_1>, whereExpr?: WhereExpr<S_1> | undefined, columns?: NonEmptyArray<keyof S_1> | undefined, orderBy?: NonEmptyArray<[keyof S_1, "ASC" | "DESC"]> | undefined) => string;
8
8
  };
9
9
  export declare function getTableName<S extends Shape>({ database, name, }: TableOptions<S>): string;
@@ -36,17 +36,19 @@ class Table {
36
36
  }
37
37
  async select({ abort_signal, clickhouse_settings, columns, order_by, where, } = {}) {
38
38
  const query = query_formatter_1.QueryFormatter.select(this.options, where, columns, order_by);
39
- const rows = await this.client.query({
39
+ const rs = await this.client.query({
40
40
  query,
41
41
  clickhouse_settings,
42
42
  abort_signal,
43
43
  format: 'JSONEachRow',
44
44
  });
45
- const stream = rows.stream();
45
+ const stream = rs.stream();
46
46
  async function* asyncGenerator() {
47
- for await (const row of stream) {
48
- const value = row.json();
49
- yield value;
47
+ for await (const rows of stream) {
48
+ for (const row of rows) {
49
+ const value = row.json();
50
+ yield value;
51
+ }
50
52
  }
51
53
  }
52
54
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"table.js","sourceRoot":"","sources":["../../src/schema/table.ts"],"names":[],"mappings":";;;AAGA,uDAAgE;AA6ChE,MAAa,KAAK;IAChB,YACmB,MAAwB,EACxB,OAAwB;;;;;mBADxB;;;;;;mBACA;;IAChB,CAAC;IAEJ,qBAAqB;IACrB,KAAK,CAAC,MAAM,CAAC,OAA8B;QACzC,MAAM,KAAK,GAAG,gCAAc,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QAC/D,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;YACtB,KAAK;YACL,mBAAmB,EAAE,OAAO,CAAC,mBAAmB;SACjD,CAAC,CAAA;IACJ,CAAC;IAED,MAAM,CAAC,EACL,YAAY,EACZ,mBAAmB,EACnB,MAAM,GACW;QACjB,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;YACxB,mBAAmB;YACnB,YAAY;YACZ,KAAK,EAAE,IAAA,8BAAY,EAAC,IAAI,CAAC,OAAO,CAAC;YACjC,MAAM,EAAE,aAAa;YACrB,MAAM;SACP,CAAC,CAAA;IACJ,CAAC;IAED,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AAM,GAAG,EAAE,CAAA;gBACjB,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,cAAc,EAAE,EAAE;oBAC1C,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;wBACxB,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,CAAA;qBACtB;yBAAM;wBACL,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;qBACnB;iBACF;gBACD,OAAO,MAAM,CAAA;YACf,CAAC;SACF,CAAA;IACH,CAAC;CACF;AArED,sBAqEC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clickhouse/client",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "Official JS client for ClickHouse DB",
5
5
  "license": "Apache-2.0",
6
6
  "keywords": [
@@ -36,8 +36,7 @@
36
36
  "dist"
37
37
  ],
38
38
  "dependencies": {
39
- "node-abort-controller": "^3.0.1",
40
- "split2": "^4.1.0"
39
+ "node-abort-controller": "^3.0.1"
41
40
  },
42
41
  "devDependencies": {
43
42
  "@types/jest": "^29.0.2",
@@ -54,8 +53,10 @@
54
53
  "jest-silent-reporter": "^0.5.0",
55
54
  "lint-staged": "^13.0.3",
56
55
  "prettier": "2.7.1",
56
+ "split2": "^4.1.0",
57
57
  "ts-jest": "^29.0.1",
58
- "ts-loader": "^9.3.1",
58
+ "ts-node": "^10.9.1",
59
+ "tsconfig-paths": "^4.1.0",
59
60
  "typescript": "^4.8.3",
60
61
  "uuid": "^9.0.0"
61
62
  },
package/dist/rows.js DELETED
@@ -1,114 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Row = exports.Rows = void 0;
7
- const stream_1 = __importDefault(require("stream"));
8
- const split2_1 = __importDefault(require("split2"));
9
- const utils_1 = require("./utils");
10
- const data_formatter_1 = require("./data_formatter");
11
- class Rows {
12
- constructor(_stream, format) {
13
- Object.defineProperty(this, "_stream", {
14
- enumerable: true,
15
- configurable: true,
16
- writable: true,
17
- value: _stream
18
- });
19
- Object.defineProperty(this, "format", {
20
- enumerable: true,
21
- configurable: true,
22
- writable: true,
23
- value: format
24
- });
25
- }
26
- /**
27
- * The method waits for all the rows to be fully loaded
28
- * and returns the result as a string.
29
- *
30
- * The method will throw if the underlying stream was already consumed
31
- * by calling the other methods
32
- */
33
- async text() {
34
- if (this._stream.readableEnded) {
35
- throw Error(streamAlreadyConsumedMessage);
36
- }
37
- return (await (0, utils_1.getAsText)(this._stream)).toString();
38
- }
39
- /**
40
- * The method waits for the all the rows to be fully loaded.
41
- * When the response is received in full, it will be decoded to return JSON.
42
- *
43
- * The method will throw if the underlying stream was already consumed
44
- * by calling the other methods
45
- */
46
- async json() {
47
- if (this._stream.readableEnded) {
48
- throw Error(streamAlreadyConsumedMessage);
49
- }
50
- return (0, data_formatter_1.decode)(await this.text(), this.format);
51
- }
52
- /**
53
- * Returns a readable stream of {@link Row}s for responses
54
- * in {@link StreamableDataFormat} format.
55
- *
56
- * The method will throw if called on a response in non-streamable format,
57
- * and if the underlying stream was already consumed
58
- * by calling the other methods
59
- */
60
- stream() {
61
- // If the underlying stream has already ended by calling `text` or `json`,
62
- // Stream.pipeline will create a new empty stream
63
- // but without "readableEnded" flag set to true
64
- if (this._stream.readableEnded) {
65
- throw Error(streamAlreadyConsumedMessage);
66
- }
67
- (0, data_formatter_1.validateStreamFormat)(this.format);
68
- return stream_1.default.pipeline(this._stream,
69
- // only JSON-based format are supported at the moment
70
- (0, split2_1.default)((row) => new Row(row, 'JSON')), function pipelineCb(err) {
71
- if (err) {
72
- console.error(err);
73
- }
74
- });
75
- }
76
- close() {
77
- this._stream.destroy();
78
- }
79
- }
80
- exports.Rows = Rows;
81
- class Row {
82
- constructor(chunk, format) {
83
- Object.defineProperty(this, "chunk", {
84
- enumerable: true,
85
- configurable: true,
86
- writable: true,
87
- value: chunk
88
- });
89
- Object.defineProperty(this, "format", {
90
- enumerable: true,
91
- configurable: true,
92
- writable: true,
93
- value: format
94
- });
95
- }
96
- /**
97
- * Returns a string representation of a row.
98
- */
99
- text() {
100
- return this.chunk;
101
- }
102
- /**
103
- * Returns a JSON representation of a row.
104
- * The method will throw if called on a response in JSON incompatible format.
105
- *
106
- * It is safe to call this method multiple times.
107
- */
108
- json() {
109
- return (0, data_formatter_1.decode)(this.text(), this.format);
110
- }
111
- }
112
- exports.Row = Row;
113
- const streamAlreadyConsumedMessage = 'Stream has been already consumed';
114
- //# sourceMappingURL=rows.js.map
package/dist/rows.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"rows.js","sourceRoot":"","sources":["../src/rows.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA2B;AAC3B,oDAA0B;AAE1B,mCAAmC;AACnC,qDAAgF;AAEhF,MAAa,IAAI;IACf,YACU,OAAwB,EACf,MAAkB;;;;;mBAD3B;;;;;;mBACS;;IAChB,CAAC;IAEJ;;;;;;OAMG;IACH,KAAK,CAAC,IAAI;QACR,IAAI,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE;YAC9B,MAAM,KAAK,CAAC,4BAA4B,CAAC,CAAA;SAC1C;QACD,OAAO,CAAC,MAAM,IAAA,iBAAS,EAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAA;IACnD,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,IAAI;QACR,IAAI,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE;YAC9B,MAAM,KAAK,CAAC,4BAA4B,CAAC,CAAA;SAC1C;QACD,OAAO,IAAA,uBAAM,EAAC,MAAM,IAAI,CAAC,IAAI,EAAE,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;IAC/C,CAAC;IAED;;;;;;;OAOG;IACH,MAAM;QACJ,0EAA0E;QAC1E,iDAAiD;QACjD,+CAA+C;QAC/C,IAAI,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE;YAC9B,MAAM,KAAK,CAAC,4BAA4B,CAAC,CAAA;SAC1C;QAED,IAAA,qCAAoB,EAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QAEjC,OAAO,gBAAM,CAAC,QAAQ,CACpB,IAAI,CAAC,OAAO;QACZ,qDAAqD;QACrD,IAAA,gBAAK,EAAC,CAAC,GAAW,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,EAC5C,SAAS,UAAU,CAAC,GAAG;YACrB,IAAI,GAAG,EAAE;gBACP,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;aACnB;QACH,CAAC,CACF,CAAA;IACH,CAAC;IAED,KAAK;QACH,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAA;IACxB,CAAC;CACF;AAnED,oBAmEC;AAED,MAAa,GAAG;IACd,YACmB,KAAa,EACb,MAAkB;;;;;mBADlB;;;;;;mBACA;;IAChB,CAAC;IAEJ;;OAEG;IACH,IAAI;QACF,OAAO,IAAI,CAAC,KAAK,CAAA;IACnB,CAAC;IAED;;;;;OAKG;IACH,IAAI;QACF,OAAO,IAAA,uBAAM,EAAC,IAAI,CAAC,IAAI,EAAE,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;IACzC,CAAC;CACF;AAtBD,kBAsBC;AAED,MAAM,4BAA4B,GAAG,kCAAkC,CAAA"}
@@ -1,3 +0,0 @@
1
- import type { Infer, Shape } from './common';
2
- export declare function compactJson<S extends Shape>(shape: S, value: Infer<S>): Infer<S>[Extract<keyof S, string>][];
3
- export declare function decompactJson<S extends Shape>(shape: S, [row]: [unknown[]]): Infer<S>;
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.decompactJson = exports.compactJson = void 0;
4
- function compactJson(shape, value) {
5
- const compacted = [];
6
- for (const key in shape) {
7
- if (key in value) {
8
- compacted.push(value[key]);
9
- }
10
- }
11
- return compacted;
12
- }
13
- exports.compactJson = compactJson;
14
- function decompactJson(shape, [row]) {
15
- const obj = {};
16
- let i = 0;
17
- for (const key in shape) {
18
- obj[key] = row[i];
19
- i++;
20
- }
21
- return obj;
22
- }
23
- exports.decompactJson = decompactJson;
24
- //# sourceMappingURL=compact.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"compact.js","sourceRoot":"","sources":["../../src/schema/compact.ts"],"names":[],"mappings":";;;AAEA,SAAgB,WAAW,CAAkB,KAAQ,EAAE,KAAe;IACpE,MAAM,SAAS,GAAG,EAAE,CAAA;IACpB,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE;QACvB,IAAI,GAAG,IAAI,KAAK,EAAE;YAChB,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAA;SAC3B;KACF;IACD,OAAO,SAAS,CAAA;AAClB,CAAC;AARD,kCAQC;AAED,SAAgB,aAAa,CAAkB,KAAQ,EAAE,CAAC,GAAG,CAAc;IACzE,MAAM,GAAG,GAA4B,EAAE,CAAA;IACvC,IAAI,CAAC,GAAG,CAAC,CAAA;IACT,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE;QACvB,GAAG,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAA;QACjB,CAAC,EAAE,CAAA;KACJ;IACD,OAAO,GAAe,CAAA;AACxB,CAAC;AARD,sCAQC"}