@clickhouse/client 1.18.1 → 1.18.2-head.9835b07.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 +3 -2
- package/dist/config.js.map +1 -1
- package/dist/connection/node_base_connection.d.ts +4 -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 +42 -0
- package/dist/connection/socket_pool.js +546 -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,8 +11,9 @@ 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;
|
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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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;
|
|
@@ -24,35 +25,13 @@ export type TLSParams = {
|
|
|
24
25
|
key: Buffer;
|
|
25
26
|
type: 'Mutual';
|
|
26
27
|
};
|
|
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
28
|
export declare abstract class NodeBaseConnection implements Connection<Stream.Readable> {
|
|
44
29
|
protected readonly params: NodeConnectionParams;
|
|
45
30
|
protected readonly agent: Http.Agent;
|
|
46
31
|
protected readonly defaultAuthHeader: string;
|
|
47
32
|
protected readonly defaultHeaders: Http.OutgoingHttpHeaders;
|
|
48
|
-
private readonly jsonHandling;
|
|
49
|
-
private readonly knownSockets;
|
|
50
|
-
private readonly idleSocketTTL;
|
|
51
33
|
private readonly connectionId;
|
|
52
|
-
private
|
|
53
|
-
private requestCounter;
|
|
54
|
-
private getNewSocketId;
|
|
55
|
-
private getNewRequestId;
|
|
34
|
+
private readonly socketPool;
|
|
56
35
|
protected constructor(params: NodeConnectionParams, agent: Http.Agent);
|
|
57
36
|
ping(params: ConnPingParams): Promise<ConnPingResult>;
|
|
58
37
|
query(params: ConnBaseQueryParams): Promise<ConnQueryResult<Stream.Readable>>;
|
|
@@ -67,7 +46,6 @@ export declare abstract class NodeBaseConnection implements Connection<Stream.Re
|
|
|
67
46
|
private getAbortController;
|
|
68
47
|
private logRequestError;
|
|
69
48
|
private httpRequestErrorMessage;
|
|
70
|
-
private parseSummary;
|
|
71
49
|
private runExec;
|
|
72
50
|
private request;
|
|
73
51
|
}
|