@clickhouse/client 1.22.0-head.bb7d9d2.1 → 1.23.0-head.b25cda1.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 +2 -1
- package/dist/client.d.ts +2 -2
- package/dist/client.js +11 -4
- package/dist/client.js.map +1 -1
- package/dist/common/clickhouse_types.d.ts +98 -0
- package/dist/common/clickhouse_types.js +30 -0
- package/dist/common/clickhouse_types.js.map +1 -0
- package/dist/common/client.d.ts +233 -0
- package/dist/common/client.js +414 -0
- package/dist/common/client.js.map +1 -0
- package/dist/common/config.d.ts +234 -0
- package/dist/common/config.js +364 -0
- package/dist/common/config.js.map +1 -0
- package/dist/common/connection.d.ts +124 -0
- package/dist/common/connection.js +3 -0
- package/dist/common/connection.js.map +1 -0
- package/dist/common/data_formatter/format_query_params.d.ts +11 -0
- package/dist/common/data_formatter/format_query_params.js +128 -0
- package/dist/common/data_formatter/format_query_params.js.map +1 -0
- package/dist/common/data_formatter/format_query_settings.d.ts +2 -0
- package/dist/common/data_formatter/format_query_settings.js +20 -0
- package/dist/common/data_formatter/format_query_settings.js.map +1 -0
- package/dist/common/data_formatter/formatter.d.ts +41 -0
- package/dist/common/data_formatter/formatter.js +78 -0
- package/dist/common/data_formatter/formatter.js.map +1 -0
- package/dist/common/data_formatter/index.d.ts +3 -0
- package/dist/common/data_formatter/index.js +24 -0
- package/dist/common/data_formatter/index.js.map +1 -0
- package/dist/common/error/error.d.ts +20 -0
- package/dist/common/error/error.js +73 -0
- package/dist/common/error/error.js.map +1 -0
- package/dist/common/error/index.d.ts +1 -0
- package/dist/common/error/index.js +18 -0
- package/dist/common/error/index.js.map +1 -0
- package/dist/common/index.d.ts +67 -0
- package/dist/common/index.js +97 -0
- package/dist/common/index.js.map +1 -0
- package/dist/common/logger.d.ts +80 -0
- package/dist/common/logger.js +154 -0
- package/dist/common/logger.js.map +1 -0
- package/dist/common/parse/column_types.d.ts +127 -0
- package/dist/common/parse/column_types.js +586 -0
- package/dist/common/parse/column_types.js.map +1 -0
- package/dist/common/parse/index.d.ts +2 -0
- package/dist/common/parse/index.js +19 -0
- package/dist/common/parse/index.js.map +1 -0
- package/dist/common/parse/json_handling.d.ts +19 -0
- package/dist/common/parse/json_handling.js +8 -0
- package/dist/common/parse/json_handling.js.map +1 -0
- package/dist/common/result.d.ts +90 -0
- package/dist/common/result.js +3 -0
- package/dist/common/result.js.map +1 -0
- package/dist/common/settings.d.ts +1990 -0
- package/dist/common/settings.js +19 -0
- package/dist/common/settings.js.map +1 -0
- package/dist/common/tracing.d.ts +146 -0
- package/dist/common/tracing.js +76 -0
- package/dist/common/tracing.js.map +1 -0
- package/dist/common/ts_utils.d.ts +4 -0
- package/dist/common/ts_utils.js +3 -0
- package/dist/common/ts_utils.js.map +1 -0
- package/dist/common/utils/connection.d.ts +21 -0
- package/dist/common/utils/connection.js +43 -0
- package/dist/common/utils/connection.js.map +1 -0
- package/dist/common/utils/index.d.ts +5 -0
- package/dist/common/utils/index.js +22 -0
- package/dist/common/utils/index.js.map +1 -0
- package/dist/common/utils/multipart.d.ts +34 -0
- package/dist/common/utils/multipart.js +81 -0
- package/dist/common/utils/multipart.js.map +1 -0
- package/dist/common/utils/sleep.d.ts +4 -0
- package/dist/common/utils/sleep.js +12 -0
- package/dist/common/utils/sleep.js.map +1 -0
- package/dist/common/utils/stream.d.ts +15 -0
- package/dist/common/utils/stream.js +50 -0
- package/dist/common/utils/stream.js.map +1 -0
- package/dist/common/utils/url.d.ts +20 -0
- package/dist/common/utils/url.js +67 -0
- package/dist/common/utils/url.js.map +1 -0
- package/dist/common/version.d.ts +2 -0
- package/dist/common/version.js +4 -0
- package/dist/common/version.js.map +1 -0
- package/dist/config.d.ts +22 -2
- package/dist/config.js +2 -2
- package/dist/config.js.map +1 -1
- package/dist/connection/compression.d.ts +2 -2
- package/dist/connection/compression.js +4 -4
- package/dist/connection/compression.js.map +1 -1
- package/dist/connection/create_connection.d.ts +1 -1
- package/dist/connection/node_base_connection.d.ts +3 -3
- package/dist/connection/node_base_connection.js +22 -22
- package/dist/connection/node_base_connection.js.map +1 -1
- package/dist/connection/node_custom_agent_connection.js +2 -2
- package/dist/connection/node_custom_agent_connection.js.map +1 -1
- package/dist/connection/node_http_connection.js +2 -2
- package/dist/connection/node_http_connection.js.map +1 -1
- package/dist/connection/node_https_connection.d.ts +1 -1
- package/dist/connection/node_https_connection.js +3 -3
- package/dist/connection/node_https_connection.js.map +1 -1
- package/dist/connection/socket_pool.d.ts +1 -1
- package/dist/connection/socket_pool.js +30 -30
- package/dist/connection/socket_pool.js.map +1 -1
- package/dist/connection/stream.d.ts +1 -1
- package/dist/connection/stream.js +9 -9
- package/dist/connection/stream.js.map +1 -1
- package/dist/index.d.ts +7 -7
- package/dist/index.js +24 -24
- package/dist/index.js.map +1 -1
- package/dist/result_set.d.ts +1 -1
- package/dist/result_set.js +10 -10
- package/dist/result_set.js.map +1 -1
- package/dist/utils/encoder.d.ts +1 -1
- package/dist/utils/encoder.js +5 -5
- package/dist/utils/encoder.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +7 -5
- package/skills/clickhouse-js-node-rowbinary-parser/EXAMPLES.md +48 -0
- package/skills/clickhouse-js-node-rowbinary-parser/README.md +248 -0
- package/skills/clickhouse-js-node-rowbinary-parser/SKILL.md +190 -0
- package/skills/clickhouse-js-node-rowbinary-parser/case-studies/iot-rowbinary-vs-json.md +83 -0
- package/skills/clickhouse-js-node-rowbinary-parser/case-studies/ledger-rowbinary-vs-json.md +103 -0
- package/skills/clickhouse-js-node-rowbinary-parser/case-studies/logs-json-wins.md +86 -0
- package/skills/clickhouse-js-node-rowbinary-parser/case-studies/wasm-vs-js.md +172 -0
- package/skills/clickhouse-js-node-rowbinary-parser/src/aggregateFunction.ts +34 -0
- package/skills/clickhouse-js-node-rowbinary-parser/src/bool.ts +10 -0
- package/skills/clickhouse-js-node-rowbinary-parser/src/columnar.ts +125 -0
- package/skills/clickhouse-js-node-rowbinary-parser/src/composite.ts +181 -0
- package/skills/clickhouse-js-node-rowbinary-parser/src/core.ts +77 -0
- package/skills/clickhouse-js-node-rowbinary-parser/src/datetime.ts +113 -0
- package/skills/clickhouse-js-node-rowbinary-parser/src/decimals.ts +57 -0
- package/skills/clickhouse-js-node-rowbinary-parser/src/dynamic.ts +328 -0
- package/skills/clickhouse-js-node-rowbinary-parser/src/enums.ts +28 -0
- package/skills/clickhouse-js-node-rowbinary-parser/src/examples/carts.ts +71 -0
- package/skills/clickhouse-js-node-rowbinary-parser/src/examples/events.ts +51 -0
- package/skills/clickhouse-js-node-rowbinary-parser/src/examples/iot.ts +158 -0
- package/skills/clickhouse-js-node-rowbinary-parser/src/examples/ledger.ts +98 -0
- package/skills/clickhouse-js-node-rowbinary-parser/src/examples/logs.ts +73 -0
- package/skills/clickhouse-js-node-rowbinary-parser/src/examples/observability.ts +142 -0
- package/skills/clickhouse-js-node-rowbinary-parser/src/examples/orders.ts +65 -0
- package/skills/clickhouse-js-node-rowbinary-parser/src/examples/profiles.ts +60 -0
- package/skills/clickhouse-js-node-rowbinary-parser/src/examples/telemetry.ts +102 -0
- package/skills/clickhouse-js-node-rowbinary-parser/src/floats.ts +32 -0
- package/skills/clickhouse-js-node-rowbinary-parser/src/geo.ts +109 -0
- package/skills/clickhouse-js-node-rowbinary-parser/src/integers.ts +95 -0
- package/skills/clickhouse-js-node-rowbinary-parser/src/interval.ts +54 -0
- package/skills/clickhouse-js-node-rowbinary-parser/src/ip.ts +93 -0
- package/skills/clickhouse-js-node-rowbinary-parser/src/json.ts +33 -0
- package/skills/clickhouse-js-node-rowbinary-parser/src/lowCardinality.ts +18 -0
- package/skills/clickhouse-js-node-rowbinary-parser/src/nested.ts +23 -0
- package/skills/clickhouse-js-node-rowbinary-parser/src/nothing.ts +29 -0
- package/skills/clickhouse-js-node-rowbinary-parser/src/reader.ts +51 -0
- package/skills/clickhouse-js-node-rowbinary-parser/src/rows.ts +58 -0
- package/skills/clickhouse-js-node-rowbinary-parser/src/simpleAggregateFunction.ts +20 -0
- package/skills/clickhouse-js-node-rowbinary-parser/src/stream.ts +276 -0
- package/skills/clickhouse-js-node-rowbinary-parser/src/strings.ts +55 -0
- package/skills/clickhouse-js-node-rowbinary-parser/src/time.ts +61 -0
- package/skills/clickhouse-js-node-rowbinary-parser/src/uuid.ts +153 -0
- package/skills/clickhouse-js-node-rowbinary-parser/src/varint.ts +70 -0
package/README.md
CHANGED
|
@@ -33,7 +33,7 @@ Official JS client for [ClickHouse](https://clickhouse.com/), written purely in
|
|
|
33
33
|
|
|
34
34
|
The client has zero external dependencies and is optimized for maximum performance.
|
|
35
35
|
|
|
36
|
-
The repository consists of
|
|
36
|
+
The repository consists of four packages:
|
|
37
37
|
|
|
38
38
|
- `@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)
|
|
39
39
|
and [Stream](https://nodejs.org/api/stream.html) APIs; supports streaming for both selects and inserts.
|
|
@@ -41,6 +41,7 @@ The repository consists of three packages:
|
|
|
41
41
|
and [Web Streams](https://developer.mozilla.org/en-US/docs/Web/API/Streams_API) APIs; supports streaming for selects.
|
|
42
42
|
Compatible with Chrome/Firefox browsers and Cloudflare workers.
|
|
43
43
|
- `@clickhouse/client-common` - shared common types and the base framework for building a custom client implementation.
|
|
44
|
+
- `@clickhouse/rowbinary` - a library for reading (and soon writing) ClickHouse RowBinary format.
|
|
44
45
|
|
|
45
46
|
## Installation
|
|
46
47
|
|
package/dist/client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { DataFormat, IsSame, QueryParamsWithFormat } from "
|
|
2
|
-
import { ClickHouseClient } from "
|
|
1
|
+
import type { DataFormat, IsSame, QueryParamsWithFormat } from "./common/index";
|
|
2
|
+
import { ClickHouseClient } from "./common/index";
|
|
3
3
|
import type Stream from "stream";
|
|
4
4
|
import type { NodeClickHouseClientConfigOptions } from "./config";
|
|
5
5
|
import type { ResultSet } from "./result_set";
|
package/dist/client.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.NodeClickHouseClient = void 0;
|
|
4
4
|
exports.createClient = createClient;
|
|
5
|
-
const
|
|
5
|
+
const index_1 = require("./common/index");
|
|
6
6
|
const config_1 = require("./config");
|
|
7
|
-
class NodeClickHouseClient extends
|
|
7
|
+
class NodeClickHouseClient extends index_1.ClickHouseClient {
|
|
8
8
|
/** See {@link ClickHouseClient.query}. */
|
|
9
9
|
query(params) {
|
|
10
10
|
return super.query(params);
|
|
@@ -12,8 +12,15 @@ class NodeClickHouseClient extends client_common_1.ClickHouseClient {
|
|
|
12
12
|
}
|
|
13
13
|
exports.NodeClickHouseClient = NodeClickHouseClient;
|
|
14
14
|
function createClient(config) {
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
// If the caller injected a pre-built Connection, override the
|
|
16
|
+
// default HTTP make_connection factory to return THAT connection
|
|
17
|
+
// instead. Used for the experimental integration with chDB only.
|
|
18
|
+
const injected = config?.connection;
|
|
19
|
+
const impl = injected !== undefined
|
|
20
|
+
? { ...config_1.NodeConfigImpl, make_connection: () => injected }
|
|
21
|
+
: config_1.NodeConfigImpl;
|
|
22
|
+
return new index_1.ClickHouseClient({
|
|
23
|
+
impl,
|
|
17
24
|
...(config || {}),
|
|
18
25
|
});
|
|
19
26
|
}
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;AAwBA,oCAeC;AAtCD,0CAAkD;AAGlD,qCAA0C;AAW1C,MAAa,oBAAqB,SAAQ,wBAAiC;IACzE,0CAA0C;IACjC,KAAK,CACZ,MAAqC;QAErC,OAAO,KAAK,CAAC,KAAK,CAAC,MAAM,CAA+B,CAAC;IAC3D,CAAC;CACF;AAPD,oDAOC;AAED,SAAgB,YAAY,CAC1B,MAA0C;IAE1C,8DAA8D;IAC9D,iEAAiE;IACjE,iEAAiE;IACjE,MAAM,QAAQ,GAAG,MAAM,EAAE,UAAU,CAAC;IACpC,MAAM,IAAI,GACR,QAAQ,KAAK,SAAS;QACpB,CAAC,CAAC,EAAE,GAAG,uBAAc,EAAE,eAAe,EAAE,GAAG,EAAE,CAAC,QAAQ,EAAE;QACxD,CAAC,CAAC,uBAAc,CAAC;IACrB,OAAO,IAAI,wBAAgB,CAAkB;QAC3C,IAAI;QACJ,GAAG,CAAC,MAAM,IAAI,EAAE,CAAC;KAClB,CAAyB,CAAC;AAC7B,CAAC"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
export interface ResponseJSON<T = unknown> {
|
|
2
|
+
data: Array<T>;
|
|
3
|
+
query_id?: string;
|
|
4
|
+
totals?: T;
|
|
5
|
+
extremes?: Record<string, any>;
|
|
6
|
+
meta?: Array<{
|
|
7
|
+
name: string;
|
|
8
|
+
type: string;
|
|
9
|
+
}>;
|
|
10
|
+
statistics?: {
|
|
11
|
+
elapsed: number;
|
|
12
|
+
rows_read: number;
|
|
13
|
+
bytes_read: number;
|
|
14
|
+
};
|
|
15
|
+
rows?: number;
|
|
16
|
+
rows_before_limit_at_least?: number;
|
|
17
|
+
}
|
|
18
|
+
export interface InputJSON<T = unknown> {
|
|
19
|
+
meta: {
|
|
20
|
+
name: string;
|
|
21
|
+
type: string;
|
|
22
|
+
}[];
|
|
23
|
+
data: T[];
|
|
24
|
+
}
|
|
25
|
+
export type InputJSONObjectEachRow<T = unknown> = Record<string, T>;
|
|
26
|
+
export interface ClickHouseSummary {
|
|
27
|
+
read_rows: string;
|
|
28
|
+
read_bytes: string;
|
|
29
|
+
written_rows: string;
|
|
30
|
+
written_bytes: string;
|
|
31
|
+
total_rows_to_read: string;
|
|
32
|
+
result_rows: string;
|
|
33
|
+
result_bytes: string;
|
|
34
|
+
elapsed_ns: string;
|
|
35
|
+
/** Available only after ClickHouse 24.9 */
|
|
36
|
+
real_time_microseconds?: string;
|
|
37
|
+
}
|
|
38
|
+
export type ResponseHeaders = Record<string, string | string[] | undefined>;
|
|
39
|
+
export interface WithClickHouseSummary {
|
|
40
|
+
summary?: ClickHouseSummary;
|
|
41
|
+
}
|
|
42
|
+
export interface WithResponseHeaders {
|
|
43
|
+
response_headers: ResponseHeaders;
|
|
44
|
+
}
|
|
45
|
+
export interface WithHttpStatusCode {
|
|
46
|
+
http_status_code?: number;
|
|
47
|
+
}
|
|
48
|
+
export interface ClickHouseProgress {
|
|
49
|
+
read_rows: string;
|
|
50
|
+
read_bytes: string;
|
|
51
|
+
elapsed_ns: string;
|
|
52
|
+
total_rows_to_read?: string;
|
|
53
|
+
}
|
|
54
|
+
export interface ProgressRow {
|
|
55
|
+
progress: ClickHouseProgress;
|
|
56
|
+
}
|
|
57
|
+
export type SpecialEventRow<T> = {
|
|
58
|
+
meta: Array<{
|
|
59
|
+
name: string;
|
|
60
|
+
type: string;
|
|
61
|
+
}>;
|
|
62
|
+
} | {
|
|
63
|
+
totals: T;
|
|
64
|
+
} | {
|
|
65
|
+
min: T;
|
|
66
|
+
} | {
|
|
67
|
+
max: T;
|
|
68
|
+
} | {
|
|
69
|
+
rows_before_limit_at_least: number | string;
|
|
70
|
+
} | {
|
|
71
|
+
rows_before_aggregation: number | string;
|
|
72
|
+
} | {
|
|
73
|
+
exception: string;
|
|
74
|
+
};
|
|
75
|
+
export type InsertValues<Stream, T = unknown> = ReadonlyArray<T> | Stream | InputJSON<T> | InputJSONObjectEachRow<T>;
|
|
76
|
+
export type NonEmptyArray<T> = [T, ...T[]];
|
|
77
|
+
export interface ClickHouseCredentialsAuth {
|
|
78
|
+
username?: string;
|
|
79
|
+
password?: string;
|
|
80
|
+
}
|
|
81
|
+
/** Supported in ClickHouse Cloud only */
|
|
82
|
+
export interface ClickHouseJWTAuth {
|
|
83
|
+
access_token: string;
|
|
84
|
+
}
|
|
85
|
+
export type ClickHouseAuth = ClickHouseCredentialsAuth | ClickHouseJWTAuth;
|
|
86
|
+
/** Type guard to use with `JSONEachRowWithProgress`, checking if the emitted row is a progress row.
|
|
87
|
+
* @see https://clickhouse.com/docs/interfaces/formats/JSONEachRowWithProgress */
|
|
88
|
+
export declare function isProgressRow(row: unknown): row is ProgressRow;
|
|
89
|
+
/** Type guard to use with `JSONEachRowWithProgress`, checking if the emitted row is a row with data.
|
|
90
|
+
* @see https://clickhouse.com/docs/interfaces/formats/JSONEachRowWithProgress */
|
|
91
|
+
export declare function isRow<T>(row: unknown): row is {
|
|
92
|
+
row: T;
|
|
93
|
+
};
|
|
94
|
+
/** Type guard to use with `JSONEachRowWithProgress`, checking if the row contains an exception.
|
|
95
|
+
* @see https://clickhouse.com/docs/interfaces/formats/JSONEachRowWithProgress */
|
|
96
|
+
export declare function isException(row: unknown): row is {
|
|
97
|
+
exception: string;
|
|
98
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isProgressRow = isProgressRow;
|
|
4
|
+
exports.isRow = isRow;
|
|
5
|
+
exports.isException = isException;
|
|
6
|
+
/** Type guard to use with `JSONEachRowWithProgress`, checking if the emitted row is a progress row.
|
|
7
|
+
* @see https://clickhouse.com/docs/interfaces/formats/JSONEachRowWithProgress */
|
|
8
|
+
function isProgressRow(row) {
|
|
9
|
+
return (row !== null &&
|
|
10
|
+
typeof row === "object" &&
|
|
11
|
+
"progress" in row &&
|
|
12
|
+
Object.keys(row).length === 1);
|
|
13
|
+
}
|
|
14
|
+
/** Type guard to use with `JSONEachRowWithProgress`, checking if the emitted row is a row with data.
|
|
15
|
+
* @see https://clickhouse.com/docs/interfaces/formats/JSONEachRowWithProgress */
|
|
16
|
+
function isRow(row) {
|
|
17
|
+
return (row !== null &&
|
|
18
|
+
typeof row === "object" &&
|
|
19
|
+
"row" in row &&
|
|
20
|
+
Object.keys(row).length === 1);
|
|
21
|
+
}
|
|
22
|
+
/** Type guard to use with `JSONEachRowWithProgress`, checking if the row contains an exception.
|
|
23
|
+
* @see https://clickhouse.com/docs/interfaces/formats/JSONEachRowWithProgress */
|
|
24
|
+
function isException(row) {
|
|
25
|
+
return (row !== null &&
|
|
26
|
+
typeof row === "object" &&
|
|
27
|
+
"exception" in row &&
|
|
28
|
+
Object.keys(row).length === 1);
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=clickhouse_types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clickhouse_types.js","sourceRoot":"","sources":["../../src/common/clickhouse_types.ts"],"names":[],"mappings":";;AAyFA,sCAOC;AAID,sBAOC;AAID,kCAOC;AA/BD;kFACkF;AAClF,SAAgB,aAAa,CAAC,GAAY;IACxC,OAAO,CACL,GAAG,KAAK,IAAI;QACZ,OAAO,GAAG,KAAK,QAAQ;QACvB,UAAU,IAAI,GAAG;QACjB,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,KAAK,CAAC,CAC9B,CAAC;AACJ,CAAC;AAED;kFACkF;AAClF,SAAgB,KAAK,CAAI,GAAY;IACnC,OAAO,CACL,GAAG,KAAK,IAAI;QACZ,OAAO,GAAG,KAAK,QAAQ;QACvB,KAAK,IAAI,GAAG;QACZ,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,KAAK,CAAC,CAC9B,CAAC;AACJ,CAAC;AAED;kFACkF;AAClF,SAAgB,WAAW,CAAC,GAAY;IACtC,OAAO,CACL,GAAG,KAAK,IAAI;QACZ,OAAO,GAAG,KAAK,QAAQ;QACvB,WAAW,IAAI,GAAG;QAClB,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,KAAK,CAAC,CAC9B,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import type { BaseClickHouseClientConfigOptions, ClickHouseSettings, ConnExecResult, IsSame, WithClickHouseSummary, WithResponseHeaders, DataFormat } from "./index";
|
|
2
|
+
import type { InsertValues, NonEmptyArray, WithHttpStatusCode } from "./clickhouse_types";
|
|
3
|
+
import type { ImplementationDetails } from "./config";
|
|
4
|
+
import type { ConnPingResult } from "./connection";
|
|
5
|
+
import type { BaseResultSet } from "./result";
|
|
6
|
+
export interface BaseQueryParams {
|
|
7
|
+
/** ClickHouse's settings that can be applied on query level. */
|
|
8
|
+
clickhouse_settings?: ClickHouseSettings;
|
|
9
|
+
/** Parameters for query binding. https://clickhouse.com/docs/en/interfaces/http/#cli-queries-with-parameters */
|
|
10
|
+
query_params?: Record<string, unknown>;
|
|
11
|
+
/** AbortSignal instance to cancel a request in progress. */
|
|
12
|
+
abort_signal?: AbortSignal;
|
|
13
|
+
/** A specific `query_id` that will be sent with this request.
|
|
14
|
+
* If it is not set, a random identifier will be generated automatically by the client. */
|
|
15
|
+
query_id?: string;
|
|
16
|
+
/** A specific ClickHouse Session id for this query.
|
|
17
|
+
* If it is not set, {@link BaseClickHouseClientConfigOptions.session_id} will be used.
|
|
18
|
+
* @default undefined (no override) */
|
|
19
|
+
session_id?: string;
|
|
20
|
+
/** A specific list of roles to use for this query.
|
|
21
|
+
* If it is not set, {@link BaseClickHouseClientConfigOptions.role} will be used.
|
|
22
|
+
* @default undefined (no override) */
|
|
23
|
+
role?: string | Array<string>;
|
|
24
|
+
/** When defined, overrides {@link BaseClickHouseClientConfigOptions.auth} for this particular request.
|
|
25
|
+
* @default undefined (no override) */
|
|
26
|
+
auth?: {
|
|
27
|
+
username: string;
|
|
28
|
+
password: string;
|
|
29
|
+
} | {
|
|
30
|
+
access_token: string;
|
|
31
|
+
};
|
|
32
|
+
/** Additional HTTP headers to attach to this particular request.
|
|
33
|
+
* Overrides the headers set in {@link BaseClickHouseClientConfigOptions.http_headers}.
|
|
34
|
+
* @default empty object */
|
|
35
|
+
http_headers?: Record<string, string>;
|
|
36
|
+
/** When defined, overrides {@link BaseClickHouseClientConfigOptions.use_multipart_params}
|
|
37
|
+
* for this particular request.
|
|
38
|
+
* @default undefined (no override) */
|
|
39
|
+
use_multipart_params?: boolean;
|
|
40
|
+
/** When defined, overrides {@link BaseClickHouseClientConfigOptions.use_multipart_params_auto}
|
|
41
|
+
* for this particular request.
|
|
42
|
+
* @default undefined (no override) */
|
|
43
|
+
use_multipart_params_auto?: boolean;
|
|
44
|
+
}
|
|
45
|
+
export interface QueryParams extends BaseQueryParams {
|
|
46
|
+
/** Statement to execute. */
|
|
47
|
+
query: string;
|
|
48
|
+
/** Format of the resulting dataset. */
|
|
49
|
+
format?: DataFormat;
|
|
50
|
+
}
|
|
51
|
+
/** Same parameters as {@link QueryParams}, but with `format` field as a type */
|
|
52
|
+
export type QueryParamsWithFormat<Format extends DataFormat> = Omit<QueryParams, "format"> & {
|
|
53
|
+
format?: Format;
|
|
54
|
+
};
|
|
55
|
+
/** If the Format is not a literal type, fall back to the default behavior of the ResultSet,
|
|
56
|
+
* allowing to call all methods with all data shapes variants,
|
|
57
|
+
* and avoiding generated types that include all possible DataFormat literal values. */
|
|
58
|
+
export type QueryResult<Stream, Format extends DataFormat> = IsSame<Format, DataFormat> extends true ? BaseResultSet<Stream, unknown> : BaseResultSet<Stream, Format>;
|
|
59
|
+
export type ExecParams = BaseQueryParams & {
|
|
60
|
+
/** Statement to execute (including the FORMAT clause). By default, the query will be sent in the request body;
|
|
61
|
+
* If {@link ExecParamsWithValues.values} are defined, the query is sent as a request parameter,
|
|
62
|
+
* and the values are sent in the request body instead. */
|
|
63
|
+
query: string;
|
|
64
|
+
/** If set to `false`, the client _will not_ decompress the response stream, even if the response compression
|
|
65
|
+
* was requested by the client via the {@link BaseClickHouseClientConfigOptions.compression.response } setting.
|
|
66
|
+
* This could be useful if the response stream is passed to another application as-is,
|
|
67
|
+
* and the decompression is handled there.
|
|
68
|
+
* @note 1) Node.js only. This setting will have no effect on the Web version.
|
|
69
|
+
* @note 2) In case of an error, the stream will be decompressed anyway, regardless of this setting.
|
|
70
|
+
* @default true */
|
|
71
|
+
decompress_response_stream?: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* If set to `true`, the client will ignore error responses from the server and return them as-is in the response stream.
|
|
74
|
+
* This could be useful if you want to handle error responses manually.
|
|
75
|
+
* @note 1) Node.js only. This setting will have no effect on the Web version.
|
|
76
|
+
* @note 2) Default behavior is to not ignore error responses, and throw an error when an error response
|
|
77
|
+
* is received. This includes decompressing the error response stream if it is compressed.
|
|
78
|
+
* @default false
|
|
79
|
+
*/
|
|
80
|
+
ignore_error_response?: boolean;
|
|
81
|
+
};
|
|
82
|
+
export type ExecParamsWithValues<Stream> = ExecParams & {
|
|
83
|
+
/** If you have a custom INSERT statement to run with `exec`, the data from this stream will be inserted.
|
|
84
|
+
*
|
|
85
|
+
* NB: the data in the stream is expected to be serialized accordingly to the FORMAT clause
|
|
86
|
+
* used in {@link ExecParams.query} in this case.
|
|
87
|
+
*
|
|
88
|
+
* @see https://clickhouse.com/docs/en/interfaces/formats */
|
|
89
|
+
values: Stream;
|
|
90
|
+
};
|
|
91
|
+
export type CommandParams = ExecParams;
|
|
92
|
+
export type CommandResult = {
|
|
93
|
+
query_id: string;
|
|
94
|
+
} & WithClickHouseSummary & WithResponseHeaders & WithHttpStatusCode;
|
|
95
|
+
export type InsertResult = {
|
|
96
|
+
/**
|
|
97
|
+
* Indicates whether the INSERT statement was executed on the server.
|
|
98
|
+
* Will be `false` if there was no data to insert.
|
|
99
|
+
* For example, if {@link InsertParams.values} was an empty array,
|
|
100
|
+
* the client does not send any requests to the server, and {@link executed} is false.
|
|
101
|
+
*/
|
|
102
|
+
executed: boolean;
|
|
103
|
+
/**
|
|
104
|
+
* Empty string if {@link executed} is false.
|
|
105
|
+
* Otherwise, either {@link InsertParams.query_id} if it was set, or the id that was generated by the client.
|
|
106
|
+
*/
|
|
107
|
+
query_id: string;
|
|
108
|
+
} & WithClickHouseSummary & WithResponseHeaders & WithHttpStatusCode;
|
|
109
|
+
export type ExecResult<Stream> = ConnExecResult<Stream>;
|
|
110
|
+
/** {@link except} field contains a non-empty list of columns to exclude when generating `(* EXCEPT (...))` clause */
|
|
111
|
+
export interface InsertColumnsExcept {
|
|
112
|
+
except: NonEmptyArray<string>;
|
|
113
|
+
}
|
|
114
|
+
export interface InsertParams<Stream = unknown, T = unknown> extends BaseQueryParams {
|
|
115
|
+
/** Name of a table to insert into. */
|
|
116
|
+
table: string;
|
|
117
|
+
/** A dataset to insert. */
|
|
118
|
+
values: InsertValues<Stream, T>;
|
|
119
|
+
/** Format of the dataset to insert. Default: `JSONCompactEachRow` */
|
|
120
|
+
format?: DataFormat;
|
|
121
|
+
/**
|
|
122
|
+
* Allows specifying which columns the data will be inserted into.
|
|
123
|
+
* Accepts either an array of strings (column names) or an object of {@link InsertColumnsExcept} type.
|
|
124
|
+
* Examples of generated queries:
|
|
125
|
+
*
|
|
126
|
+
* - An array such as `['a', 'b']` will generate: `INSERT INTO table (a, b) FORMAT DataFormat`
|
|
127
|
+
* - An object such as `{ except: ['a', 'b'] }` will generate: `INSERT INTO table (* EXCEPT (a, b)) FORMAT DataFormat`
|
|
128
|
+
*
|
|
129
|
+
* By default, the data is inserted into all columns of the {@link InsertParams.table},
|
|
130
|
+
* and the generated statement will be: `INSERT INTO table FORMAT DataFormat`.
|
|
131
|
+
*
|
|
132
|
+
* See also: https://clickhouse.com/docs/en/sql-reference/statements/insert-into */
|
|
133
|
+
columns?: NonEmptyArray<string> | InsertColumnsExcept;
|
|
134
|
+
}
|
|
135
|
+
/** Parameters for the health-check request - using the built-in `/ping` endpoint.
|
|
136
|
+
* This is the default behavior for the Node.js version. */
|
|
137
|
+
export type PingParamsWithEndpoint = {
|
|
138
|
+
select: false;
|
|
139
|
+
} & Pick<BaseQueryParams, "abort_signal" | "http_headers">;
|
|
140
|
+
/** Parameters for the health-check request - using a SELECT query.
|
|
141
|
+
* This is the default behavior for the Web version, as the `/ping` endpoint does not support CORS.
|
|
142
|
+
* Most of the standard `query` method params, e.g., `query_id`, `abort_signal`, `http_headers`, etc. will work,
|
|
143
|
+
* except for `query_params`, which does not make sense to allow in this method. */
|
|
144
|
+
export type PingParamsWithSelectQuery = {
|
|
145
|
+
select: true;
|
|
146
|
+
} & Omit<BaseQueryParams, "query_params">;
|
|
147
|
+
export type PingParams = PingParamsWithEndpoint | PingParamsWithSelectQuery;
|
|
148
|
+
export type PingResult = ConnPingResult;
|
|
149
|
+
export declare class ClickHouseClient<Stream = unknown> {
|
|
150
|
+
private readonly clientClickHouseSettings;
|
|
151
|
+
private readonly connectionParams;
|
|
152
|
+
private readonly connection;
|
|
153
|
+
private readonly makeResultSet;
|
|
154
|
+
private readonly valuesEncoder;
|
|
155
|
+
private readonly sessionId?;
|
|
156
|
+
private readonly role?;
|
|
157
|
+
private readonly jsonHandling;
|
|
158
|
+
private readonly tracer;
|
|
159
|
+
constructor(config: BaseClickHouseClientConfigOptions & ImplementationDetails<Stream>);
|
|
160
|
+
/**
|
|
161
|
+
* Used for most statements that can have a response, such as `SELECT`.
|
|
162
|
+
* Returns an implementation of {@link BaseResultSet}.
|
|
163
|
+
*
|
|
164
|
+
* The `FORMAT` clause should be specified separately via {@link QueryParams.format} (default is `JSON`);
|
|
165
|
+
* this method will always append `FORMAT <format>` to the end of {@link QueryParams.query}.
|
|
166
|
+
* If the query already contains a `FORMAT` clause, ClickHouse will return a syntax error due to a duplicate `FORMAT`.
|
|
167
|
+
* This is intended behavior.
|
|
168
|
+
* Use {@link ClickHouseClient.insert} for data insertion, {@link ClickHouseClient.command} for DDLs,
|
|
169
|
+
* or {@link ClickHouseClient.exec} for queries where you need to provide the full SQL (including `FORMAT`) yourself or where the `FORMAT` suffix is not supported.
|
|
170
|
+
*
|
|
171
|
+
* @note For `SHOW [ROW] POLICIES`, use the full syntax `SHOW POLICIES ON *`,
|
|
172
|
+
* as the short version does not support appending `FORMAT` at the server SQL parser level.
|
|
173
|
+
* See https://github.com/ClickHouse/ClickHouse/issues/105899
|
|
174
|
+
*
|
|
175
|
+
* See {@link DataFormat} for the formats supported by the client.
|
|
176
|
+
*/
|
|
177
|
+
query<Format extends DataFormat = "JSON">(params: QueryParamsWithFormat<Format>): Promise<QueryResult<Stream, Format>>;
|
|
178
|
+
/**
|
|
179
|
+
* It should be used for statements that do not have any output,
|
|
180
|
+
* when the format clause is not applicable, or when you are not interested in the response at all.
|
|
181
|
+
* The response stream is destroyed immediately as we do not expect useful information there.
|
|
182
|
+
* Examples of such statements are DDLs or custom inserts.
|
|
183
|
+
*
|
|
184
|
+
* @note if you have a custom query that does not work with {@link ClickHouseClient.query},
|
|
185
|
+
* and you are interested in the response data, consider using {@link ClickHouseClient.exec}.
|
|
186
|
+
*/
|
|
187
|
+
command(params: CommandParams): Promise<CommandResult>;
|
|
188
|
+
/**
|
|
189
|
+
* Similar to {@link ClickHouseClient.command}, but for the cases where the output _is expected_,
|
|
190
|
+
* but format clause is not applicable. The caller of this method _must_ consume the stream,
|
|
191
|
+
* as the underlying socket will not be released until then, and the request will eventually be timed out.
|
|
192
|
+
*
|
|
193
|
+
* @note it is not intended to use this method to execute the DDLs, such as `CREATE TABLE` or similar;
|
|
194
|
+
* use {@link ClickHouseClient.command} instead.
|
|
195
|
+
*/
|
|
196
|
+
exec(params: ExecParams | ExecParamsWithValues<Stream>): Promise<ExecResult<Stream>>;
|
|
197
|
+
/**
|
|
198
|
+
* The primary method for data insertion. It is recommended to avoid arrays in case of large inserts
|
|
199
|
+
* to reduce application memory consumption and consider streaming for most of such use cases.
|
|
200
|
+
* As the insert operation does not provide any output, the response stream is immediately destroyed.
|
|
201
|
+
*
|
|
202
|
+
* @note in case of a custom insert operation (e.g., `INSERT FROM SELECT`),
|
|
203
|
+
* consider using {@link ClickHouseClient.command}, passing the entire raw query there
|
|
204
|
+
* (including the `FORMAT` clause).
|
|
205
|
+
*/
|
|
206
|
+
insert<T>(params: InsertParams<Stream, T>): Promise<InsertResult>;
|
|
207
|
+
/**
|
|
208
|
+
* A health-check request. It does not throw if an error occurs - the error is returned inside the result object.
|
|
209
|
+
*
|
|
210
|
+
* By default, Node.js version uses the built-in `/ping` endpoint, which does not verify credentials.
|
|
211
|
+
* Optionally, it can be switched to a `SELECT` query (see {@link PingParamsWithSelectQuery}).
|
|
212
|
+
* In that case, the server will verify the credentials.
|
|
213
|
+
*
|
|
214
|
+
* **NOTE**: Since the `/ping` endpoint does not support CORS, the Web version always uses a `SELECT` query.
|
|
215
|
+
*/
|
|
216
|
+
ping(params?: PingParams): Promise<PingResult>;
|
|
217
|
+
/**
|
|
218
|
+
* Shuts down the underlying connection.
|
|
219
|
+
* This method should ideally be called only once per application lifecycle,
|
|
220
|
+
* for example, during the graceful shutdown phase.
|
|
221
|
+
*/
|
|
222
|
+
close(): Promise<void>;
|
|
223
|
+
/**
|
|
224
|
+
* Closes the client connection.
|
|
225
|
+
*
|
|
226
|
+
* Automatically called when using `using` statement in supported environments.
|
|
227
|
+
* @see {@link ClickHouseClient.close}
|
|
228
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/using
|
|
229
|
+
*/
|
|
230
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
231
|
+
private withBaseSpanAttributes;
|
|
232
|
+
private withClientQueryParams;
|
|
233
|
+
}
|