@clickhouse/client 1.18.1 → 1.18.2-head.084b623.1
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 +67 -2
- package/dist/config.d.ts +8 -2
- package/dist/config.js +1 -0
- package/dist/config.js.map +1 -1
- package/dist/connection/create_connection.d.ts +2 -1
- package/dist/connection/create_connection.js +4 -1
- package/dist/connection/create_connection.js.map +1 -1
- package/dist/connection/node_base_connection.d.ts +8 -26
- package/dist/connection/node_base_connection.js +8 -454
- package/dist/connection/node_base_connection.js.map +1 -1
- package/dist/connection/node_custom_agent_connection.d.ts +2 -1
- package/dist/connection/node_custom_agent_connection.js.map +1 -1
- package/dist/connection/node_http_connection.d.ts +2 -1
- package/dist/connection/node_http_connection.js.map +1 -1
- package/dist/connection/node_https_connection.d.ts +2 -1
- package/dist/connection/node_https_connection.js.map +1 -1
- package/dist/connection/socket_pool.d.ts +43 -0
- package/dist/connection/socket_pool.js +623 -0
- package/dist/connection/socket_pool.js.map +1 -0
- package/dist/utils/stream.js +14 -13
- package/dist/utils/stream.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -27,18 +27,83 @@
|
|
|
27
27
|
|
|
28
28
|
Official JS client for [ClickHouse](https://clickhouse.com/), written purely in TypeScript, thoroughly tested with actual ClickHouse versions.
|
|
29
29
|
|
|
30
|
+
The client has zero external dependencies and is optimized for maximum performance.
|
|
31
|
+
|
|
30
32
|
The repository consists of three packages:
|
|
31
33
|
|
|
32
34
|
- `@clickhouse/client` - a version of the client designed for Node.js platform only. It is built on top of [HTTP](https://nodejs.org/api/http.html)
|
|
33
35
|
and [Stream](https://nodejs.org/api/stream.html) APIs; supports streaming for both selects and inserts.
|
|
34
36
|
- `@clickhouse/client-web` - a version of the client built on top of [Fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)
|
|
35
37
|
and [Web Streams](https://developer.mozilla.org/en-US/docs/Web/API/Streams_API) APIs; supports streaming for selects.
|
|
36
|
-
Compatible with Chrome/Firefox browsers and
|
|
38
|
+
Compatible with Chrome/Firefox browsers and Cloudflare workers.
|
|
37
39
|
- `@clickhouse/client-common` - shared common types and the base framework for building a custom client implementation.
|
|
38
40
|
|
|
41
|
+
## Installation
|
|
42
|
+
|
|
43
|
+
Node.js client:
|
|
44
|
+
|
|
45
|
+
```sh
|
|
46
|
+
npm i @clickhouse/client
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Web client (browsers, Cloudflare workers):
|
|
50
|
+
|
|
51
|
+
```sh
|
|
52
|
+
npm i @clickhouse/client-web
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Environment requirements
|
|
56
|
+
|
|
57
|
+
### Node.js
|
|
58
|
+
|
|
59
|
+
Node.js must be available in the environment to run the Node.js client. The client is compatible with all the [maintained](https://github.com/nodejs/release#readme) Node.js releases.
|
|
60
|
+
|
|
61
|
+
| Node.js version | Supported? |
|
|
62
|
+
| --------------- | ----------- |
|
|
63
|
+
| 24.x | ✔ |
|
|
64
|
+
| 22.x | ✔ |
|
|
65
|
+
| 20.x | ✔ |
|
|
66
|
+
| 18.x | Best effort |
|
|
67
|
+
|
|
68
|
+
### TypeScript
|
|
69
|
+
|
|
70
|
+
If using TypeScript, version [4.5](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-5.html) or above is required to enable [inline import and export syntax](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-5.html#type-modifiers-on-import-names).
|
|
71
|
+
|
|
72
|
+
## Compatibility with ClickHouse
|
|
73
|
+
|
|
74
|
+
| Client version | ClickHouse |
|
|
75
|
+
| -------------- | ---------- |
|
|
76
|
+
| 1.12.0+ | 24.8+ |
|
|
77
|
+
|
|
78
|
+
The client may work with older versions too; however, this is best-effort support and is not guaranteed.
|
|
79
|
+
|
|
80
|
+
## Quick start
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
import { createClient } from '@clickhouse/client' // or '@clickhouse/client-web'
|
|
84
|
+
|
|
85
|
+
const client = createClient({
|
|
86
|
+
url: process.env.CLICKHOUSE_URL ?? 'http://localhost:8123',
|
|
87
|
+
username: process.env.CLICKHOUSE_USER ?? 'default',
|
|
88
|
+
password: process.env.CLICKHOUSE_PASSWORD ?? '',
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
const resultSet = await client.query({
|
|
92
|
+
query: 'SELECT * FROM system.tables',
|
|
93
|
+
format: 'JSONEachRow',
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
const tables = await resultSet.json()
|
|
97
|
+
console.log(tables)
|
|
98
|
+
|
|
99
|
+
await client.close()
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
See more examples in the [examples directory](./examples).
|
|
103
|
+
|
|
39
104
|
## Documentation
|
|
40
105
|
|
|
41
|
-
See the [ClickHouse website](https://clickhouse.com/docs/
|
|
106
|
+
See the [ClickHouse website](https://clickhouse.com/docs/integrations/javascript) for the full documentation.
|
|
42
107
|
|
|
43
108
|
## Usage examples
|
|
44
109
|
|
package/dist/config.d.ts
CHANGED
|
@@ -11,11 +11,17 @@ export type NodeClickHouseClientConfigOptions = BaseClickHouseClientConfigOption
|
|
|
11
11
|
* @default true */
|
|
12
12
|
enabled?: boolean;
|
|
13
13
|
/** For how long keep a particular idle socket alive on the client side (in milliseconds).
|
|
14
|
-
* It is supposed to be a
|
|
15
|
-
* which is by default 3000 ms for pre-23.11 versions.
|
|
14
|
+
* It is supposed to be at least a second less than the ClickHouse server KeepAlive timeout,
|
|
15
|
+
* which is by default `3000` ms for pre-23.11 versions.
|
|
16
|
+
*
|
|
16
17
|
* When set to `0`, the idle socket management feature is disabled.
|
|
17
18
|
* @default 2500 */
|
|
18
19
|
idle_socket_ttl?: number;
|
|
20
|
+
/** Eagerly destroy the sockets that are considered stale (idle for more than `idle_socket_ttl`),
|
|
21
|
+
* without waiting for the timeout to trigger. This allows freeing up stale sockets
|
|
22
|
+
* in case of longer event loop delays.
|
|
23
|
+
* @default false */
|
|
24
|
+
eagerly_destroy_stale_sockets?: boolean;
|
|
19
25
|
};
|
|
20
26
|
/** Custom HTTP agent to use for the outgoing HTTP(s) requests.
|
|
21
27
|
* If set, {@link BaseClickHouseClientConfigOptions.max_open_connections}, {@link tls} and {@link keep_alive}
|
package/dist/config.js
CHANGED
|
@@ -62,6 +62,7 @@ exports.NodeConfigImpl = {
|
|
|
62
62
|
connection_params: params,
|
|
63
63
|
set_basic_auth_header: nodeConfig.set_basic_auth_header ?? true,
|
|
64
64
|
capture_enhanced_stack_trace: nodeConfig.capture_enhanced_stack_trace ?? false,
|
|
65
|
+
eagerly_destroy_stale_sockets: nodeConfig.keep_alive?.eagerly_destroy_stale_sockets ?? false,
|
|
65
66
|
http_agent: nodeConfig.http_agent,
|
|
66
67
|
keep_alive,
|
|
67
68
|
tls,
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;;AAMA,6DAIkC;AAIlC,6CAAoE;AACpE,6CAAwC;AACxC,mCAA2C;
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;;AAMA,6DAIkC;AAIlC,6CAAoE;AACpE,6CAAwC;AACxC,mCAA2C;AAyD9B,QAAA,cAAc,GAEvB;IACF,0BAA0B,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE;QAC1C,MAAM,UAAU,GAAsC,EAAE,GAAG,MAAM,EAAE,CAAA;QACnE,MAAM,aAAa,GAAG,IAAI,GAAG,EAAU,CAAA;QACvC,MAAM,aAAa,GAAG,IAAI,GAAG,EAAU,CAAA;QACvC,MAAM,mBAAmB,GAAG,CAAC,GAAG,GAAG,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC,CAAA;QACxD,IAAI,mBAAmB,CAAC,MAAM,GAA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AO,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,IAAI,IAAI;YAChD,eAAe,EAAE,UAAU,EAAE,UAAU,EAAE,eAAe,IAAI,IAAI;SACjE,CAAA;QACD,OAAO,kCAAqB,CAAC,MAAM,CAAC;YAClC,iBAAiB,EAAE,MAAM;YACzB,qBAAqB,EAAE,UAAU,CAAC,qBAAqB,IAAI,IAAI;YAC/D,4BAA4B,EAC1B,UAAU,CAAC,4BAA4B,IAAI,KAAK;YAClD,6BAA6B,EAC3B,UAAU,CAAC,UAAU,EAAE,6BAA6B,IAAI,KAAK;YAC/D,UAAU,EAAE,UAAU,CAAC,UAAU;YACjC,UAAU;YACV,GAAG;SACJ,CAAC,CAAA;IACJ,CAAC;IACD,cAAc,EAAE,CAAC,YAA0B,EAAE,EAAE,CAC7C,IAAI,yBAAiB,CAAC,YAAY,CAAC;IACrC,eAAe,EAAE,CAAC,CAChB,MAAuB,EACvB,MAAkB,EAClB,QAAgB,EAChB,SAA+B,EAC/B,gBAAiC,EACjC,YAA0B,EAC1B,EAAE,CACF,sBAAS,CAAC,QAAQ,CAAC;QACjB,MAAM;QACN,MAAM;QACN,QAAQ;QACR,SAAS;QACT,gBAAgB;QAChB,YAAY;KACb,CAAC,CAAQ;CACb,CAAA"}
|
|
@@ -9,8 +9,9 @@ export interface CreateConnectionParams {
|
|
|
9
9
|
http_agent: http.Agent | https.Agent | undefined;
|
|
10
10
|
set_basic_auth_header: boolean;
|
|
11
11
|
capture_enhanced_stack_trace: boolean;
|
|
12
|
+
eagerly_destroy_stale_sockets?: boolean;
|
|
12
13
|
}
|
|
13
14
|
/** A factory for easier mocking after Node.js 22.18 */
|
|
14
15
|
export declare class NodeConnectionFactory {
|
|
15
|
-
static create({ connection_params, tls, keep_alive, http_agent, set_basic_auth_header, capture_enhanced_stack_trace, }: CreateConnectionParams): NodeBaseConnection;
|
|
16
|
+
static create({ connection_params, tls, keep_alive, http_agent, set_basic_auth_header, capture_enhanced_stack_trace, eagerly_destroy_stale_sockets, }: CreateConnectionParams): NodeBaseConnection;
|
|
16
17
|
}
|
|
@@ -7,7 +7,7 @@ const node_https_connection_1 = require("./node_https_connection");
|
|
|
7
7
|
/** A factory for easier mocking after Node.js 22.18 */
|
|
8
8
|
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
|
|
9
9
|
class NodeConnectionFactory {
|
|
10
|
-
static create({ connection_params, tls, keep_alive, http_agent, set_basic_auth_header, capture_enhanced_stack_trace, }) {
|
|
10
|
+
static create({ connection_params, tls, keep_alive, http_agent, set_basic_auth_header, capture_enhanced_stack_trace, eagerly_destroy_stale_sockets = false, }) {
|
|
11
11
|
if (http_agent !== undefined) {
|
|
12
12
|
return new node_custom_agent_connection_1.NodeCustomAgentConnection({
|
|
13
13
|
...connection_params,
|
|
@@ -15,6 +15,7 @@ class NodeConnectionFactory {
|
|
|
15
15
|
capture_enhanced_stack_trace,
|
|
16
16
|
keep_alive, // only used to enforce proper KeepAlive headers
|
|
17
17
|
http_agent,
|
|
18
|
+
eagerly_destroy_stale_sockets,
|
|
18
19
|
});
|
|
19
20
|
}
|
|
20
21
|
switch (connection_params.url.protocol) {
|
|
@@ -24,6 +25,7 @@ class NodeConnectionFactory {
|
|
|
24
25
|
set_basic_auth_header,
|
|
25
26
|
capture_enhanced_stack_trace,
|
|
26
27
|
keep_alive,
|
|
28
|
+
eagerly_destroy_stale_sockets,
|
|
27
29
|
});
|
|
28
30
|
case 'https:':
|
|
29
31
|
return new node_https_connection_1.NodeHttpsConnection({
|
|
@@ -32,6 +34,7 @@ class NodeConnectionFactory {
|
|
|
32
34
|
capture_enhanced_stack_trace,
|
|
33
35
|
keep_alive,
|
|
34
36
|
tls,
|
|
37
|
+
eagerly_destroy_stale_sockets,
|
|
35
38
|
});
|
|
36
39
|
default:
|
|
37
40
|
throw new Error('Only HTTP and HTTPS protocols are supported');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create_connection.js","sourceRoot":"","sources":["../../src/connection/create_connection.ts"],"names":[],"mappings":";;;AAOA,iFAA0E;AAC1E,iEAA2D;AAC3D,mEAA6D;
|
|
1
|
+
{"version":3,"file":"create_connection.js","sourceRoot":"","sources":["../../src/connection/create_connection.ts"],"names":[],"mappings":";;;AAOA,iFAA0E;AAC1E,iEAA2D;AAC3D,mEAA6D;AAY7D,uDAAuD;AACvD,kEAAkE;AAClE,MAAa,qBAAqB;IAChC,MAAM,CAAC,MAAM,CAAC,EACZ,iBAAiB,EACjB,GAAG,EACH,UAAU,EACV,UAAU,EACV,qBAAqB,EACrB,4BAA4B,EAC5B,6BAA6B,GAAG,KAAK,GACd;QACvB,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;YAC7B,OAAO,IAAI,wDAAyB,CAAC;gBACnC,GAAG,iBAAiB;gBACpB,qBAAqB;gBACrB,4BAA4B;gBAC5B,UAAU,EAAE,gDAAgD;gBAC5D,UAAU;gBACV,6BAA6B;aAC9B,CAAC,CAAA;QACJ,CAAC;QACD,QAAQ,iBAAiB,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;YACvC,KAAK,OAAO;gBACV,OAAO,IAAI,yCAAkB,CAAC;oBAC5B,GAAG,iBAAiB;oBACpB,qBAAqB;oBACrB,4BAA4B;oBAC5B,UAAU;oBACV,6BAA6B;iBAC9B,CAAC,CAAA;YACJ,KAAK,QAAQ;gBACX,OAAO,IAAI,2CAAmB,CAAC;oBAC7B,GAAG,iBAAiB;oBACpB,qBAAqB;oBACrB,4BAA4B;oBAC5B,UAAU;oBACV,GAAG;oBACH,6BAA6B;iBAC9B,CAAC,CAAA;YACJ;gBACE,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAA;QAClE,CAAC;IACH,CAAC;CACF;AA1CD,sDA0CC"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import type { ConnBaseQueryParams, ConnCommandResult, Connection, ConnectionParams, ConnExecParams, ConnExecResult, ConnInsertParams, ConnInsertResult, ConnPingResult, ConnQueryResult
|
|
1
|
+
import type { ConnBaseQueryParams, ConnCommandResult, Connection, ConnectionParams, ConnExecParams, ConnExecResult, ConnInsertParams, ConnInsertResult, ConnPingResult, ConnQueryResult } from '@clickhouse/client-common';
|
|
2
2
|
import { ClickHouseLogLevel } from '@clickhouse/client-common';
|
|
3
3
|
import { type ConnPingParams } from '@clickhouse/client-common';
|
|
4
4
|
import type Http from 'http';
|
|
5
5
|
import type Https from 'node:https';
|
|
6
|
-
import Stream from 'stream';
|
|
6
|
+
import type Stream from 'stream';
|
|
7
|
+
import { type RequestParams } from './socket_pool';
|
|
7
8
|
export type NodeConnectionParams = ConnectionParams & {
|
|
8
9
|
tls?: TLSParams;
|
|
9
10
|
http_agent?: Http.Agent | Https.Agent;
|
|
@@ -14,6 +15,10 @@ export type NodeConnectionParams = ConnectionParams & {
|
|
|
14
15
|
idle_socket_ttl: number;
|
|
15
16
|
};
|
|
16
17
|
log_level: ClickHouseLogLevel;
|
|
18
|
+
/**
|
|
19
|
+
* Eagerly destroy the sockets that are considered stale (idle for more than `idle_socket_ttl`), without waiting for the timeout to trigger. This allows to free up the stale sockets in case of longer event loop delays.
|
|
20
|
+
*/
|
|
21
|
+
eagerly_destroy_stale_sockets: boolean;
|
|
17
22
|
};
|
|
18
23
|
export type TLSParams = {
|
|
19
24
|
ca_cert: Buffer;
|
|
@@ -24,35 +29,13 @@ export type TLSParams = {
|
|
|
24
29
|
key: Buffer;
|
|
25
30
|
type: 'Mutual';
|
|
26
31
|
};
|
|
27
|
-
export interface RequestParams {
|
|
28
|
-
method: 'GET' | 'POST';
|
|
29
|
-
url: URL;
|
|
30
|
-
headers: Http.OutgoingHttpHeaders;
|
|
31
|
-
body?: string | Stream.Readable;
|
|
32
|
-
abort_signal: AbortSignal;
|
|
33
|
-
enable_response_compression?: boolean;
|
|
34
|
-
enable_request_compression?: boolean;
|
|
35
|
-
try_decompress_response_stream?: boolean;
|
|
36
|
-
ignore_error_response?: boolean;
|
|
37
|
-
parse_summary?: boolean;
|
|
38
|
-
query: string;
|
|
39
|
-
query_id: string;
|
|
40
|
-
log_writer: LogWriter;
|
|
41
|
-
log_level: ClickHouseLogLevel;
|
|
42
|
-
}
|
|
43
32
|
export declare abstract class NodeBaseConnection implements Connection<Stream.Readable> {
|
|
44
33
|
protected readonly params: NodeConnectionParams;
|
|
45
34
|
protected readonly agent: Http.Agent;
|
|
46
35
|
protected readonly defaultAuthHeader: string;
|
|
47
36
|
protected readonly defaultHeaders: Http.OutgoingHttpHeaders;
|
|
48
|
-
private readonly jsonHandling;
|
|
49
|
-
private readonly knownSockets;
|
|
50
|
-
private readonly idleSocketTTL;
|
|
51
37
|
private readonly connectionId;
|
|
52
|
-
private
|
|
53
|
-
private requestCounter;
|
|
54
|
-
private getNewSocketId;
|
|
55
|
-
private getNewRequestId;
|
|
38
|
+
private readonly socketPool;
|
|
56
39
|
protected constructor(params: NodeConnectionParams, agent: Http.Agent);
|
|
57
40
|
ping(params: ConnPingParams): Promise<ConnPingResult>;
|
|
58
41
|
query(params: ConnBaseQueryParams): Promise<ConnQueryResult<Stream.Readable>>;
|
|
@@ -67,7 +50,6 @@ export declare abstract class NodeBaseConnection implements Connection<Stream.Re
|
|
|
67
50
|
private getAbortController;
|
|
68
51
|
private logRequestError;
|
|
69
52
|
private httpRequestErrorMessage;
|
|
70
|
-
private parseSummary;
|
|
71
53
|
private runExec;
|
|
72
54
|
private request;
|
|
73
55
|
}
|