@clickhouse/client-common 0.2.6 → 0.2.8
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/dist/clickhouse_types.d.ts +13 -0
- package/dist/client.d.ts +25 -6
- package/dist/client.js +23 -3
- package/dist/client.js.map +1 -1
- package/dist/connection.d.ts +3 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -22,3 +22,16 @@ export interface InputJSON<T = unknown> {
|
|
|
22
22
|
data: T[];
|
|
23
23
|
}
|
|
24
24
|
export type InputJSONObjectEachRow<T = unknown> = Record<string, T>;
|
|
25
|
+
export interface ClickHouseSummary {
|
|
26
|
+
read_rows: string;
|
|
27
|
+
read_bytes: string;
|
|
28
|
+
written_rows: string;
|
|
29
|
+
written_bytes: string;
|
|
30
|
+
total_rows_to_read: string;
|
|
31
|
+
result_rows: string;
|
|
32
|
+
result_bytes: string;
|
|
33
|
+
elapsed_ns: string;
|
|
34
|
+
}
|
|
35
|
+
export interface WithClickHouseSummary {
|
|
36
|
+
summary?: ClickHouseSummary;
|
|
37
|
+
}
|
package/dist/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ClickHouseLogLevel, ClickHouseSettings, Connection, ConnectionParams,
|
|
1
|
+
import type { ClickHouseLogLevel, ClickHouseSettings, Connection, ConnectionParams, ConnExecResult, ConnInsertResult, Logger, WithClickHouseSummary } from '@clickhouse/client-common';
|
|
2
2
|
import { type DataFormat } from '@clickhouse/client-common';
|
|
3
3
|
import type { InputJSON, InputJSONObjectEachRow } from './clickhouse_types';
|
|
4
4
|
import type { ConnPingResult } from './connection';
|
|
@@ -45,7 +45,7 @@ export interface ClickHouseClientConfigOptions<Stream> {
|
|
|
45
45
|
username?: string;
|
|
46
46
|
/** The user password. Default: ''. */
|
|
47
47
|
password?: string;
|
|
48
|
-
/** The name of the application using the
|
|
48
|
+
/** The name of the application using the JS client.
|
|
49
49
|
* Default: empty. */
|
|
50
50
|
application?: string;
|
|
51
51
|
/** Database name to use. Default value: `default`. */
|
|
@@ -85,20 +85,38 @@ export interface ExecParams extends BaseQueryParams {
|
|
|
85
85
|
query: string;
|
|
86
86
|
}
|
|
87
87
|
export type CommandParams = ExecParams;
|
|
88
|
-
export
|
|
88
|
+
export type CommandResult = {
|
|
89
89
|
query_id: string;
|
|
90
|
-
}
|
|
90
|
+
} & WithClickHouseSummary;
|
|
91
91
|
export type InsertResult = ConnInsertResult;
|
|
92
|
-
export type ExecResult<Stream> =
|
|
92
|
+
export type ExecResult<Stream> = ConnExecResult<Stream>;
|
|
93
93
|
export type PingResult = ConnPingResult;
|
|
94
94
|
export type InsertValues<Stream, T = unknown> = ReadonlyArray<T> | Stream | InputJSON<T> | InputJSONObjectEachRow<T>;
|
|
95
|
+
type NonEmptyArray<T> = [T, ...T[]];
|
|
96
|
+
/** {@link except} field contains a non-empty list of columns to exclude when generating `(* EXCEPT (...))` clause */
|
|
97
|
+
export interface InsertColumnsExcept {
|
|
98
|
+
except: NonEmptyArray<string>;
|
|
99
|
+
}
|
|
95
100
|
export interface InsertParams<Stream = unknown, T = unknown> extends BaseQueryParams {
|
|
96
101
|
/** Name of a table to insert into. */
|
|
97
102
|
table: string;
|
|
98
103
|
/** A dataset to insert. */
|
|
99
104
|
values: InsertValues<Stream, T>;
|
|
100
|
-
/** Format of the dataset to insert. */
|
|
105
|
+
/** Format of the dataset to insert. Default: `JSONCompactEachRow` */
|
|
101
106
|
format?: DataFormat;
|
|
107
|
+
/**
|
|
108
|
+
* Allows to specify which columns the data will be inserted into.
|
|
109
|
+
* Accepts either an array of strings (column names) or an object of {@link InsertColumnsExcept} type.
|
|
110
|
+
* Examples of generated queries:
|
|
111
|
+
*
|
|
112
|
+
* - An array such as `['a', 'b']` will generate: `INSERT INTO table (a, b) FORMAT DataFormat`
|
|
113
|
+
* - An object such as `{ except: ['a', 'b'] }` will generate: `INSERT INTO table (* EXCEPT (a, b)) FORMAT DataFormat`
|
|
114
|
+
*
|
|
115
|
+
* By default, the data is inserted into all columns of the {@link InsertParams.table},
|
|
116
|
+
* and the generated statement will be: `INSERT INTO table FORMAT DataFormat`.
|
|
117
|
+
*
|
|
118
|
+
* See also: https://clickhouse.com/docs/en/sql-reference/statements/insert-into */
|
|
119
|
+
columns?: NonEmptyArray<string> | InsertColumnsExcept;
|
|
102
120
|
}
|
|
103
121
|
export declare class ClickHouseClient<Stream = unknown> {
|
|
104
122
|
private readonly connectionParams;
|
|
@@ -150,3 +168,4 @@ export declare class ClickHouseClient<Stream = unknown> {
|
|
|
150
168
|
*/
|
|
151
169
|
close(): Promise<void>;
|
|
152
170
|
}
|
|
171
|
+
export {};
|
package/dist/client.js
CHANGED
|
@@ -83,9 +83,9 @@ class ClickHouseClient {
|
|
|
83
83
|
* If you are interested in the response data, consider using {@link ClickHouseClient.exec}
|
|
84
84
|
*/
|
|
85
85
|
async command(params) {
|
|
86
|
-
const { stream, query_id } = await this.exec(params);
|
|
86
|
+
const { stream, query_id, summary } = await this.exec(params);
|
|
87
87
|
await this.closeStream(stream);
|
|
88
|
-
return { query_id };
|
|
88
|
+
return { query_id, summary };
|
|
89
89
|
}
|
|
90
90
|
/**
|
|
91
91
|
* Similar to {@link ClickHouseClient.command}, but for the cases where the output is expected,
|
|
@@ -109,7 +109,7 @@ class ClickHouseClient {
|
|
|
109
109
|
async insert(params) {
|
|
110
110
|
const format = params.format || 'JSONCompactEachRow';
|
|
111
111
|
this.valuesEncoder.validateInsertValues(params.values, format);
|
|
112
|
-
const query =
|
|
112
|
+
const query = getInsertQuery(params, format);
|
|
113
113
|
return await this.connection.insert({
|
|
114
114
|
query,
|
|
115
115
|
values: this.valuesEncoder.encodeValues(params.values, format),
|
|
@@ -183,4 +183,24 @@ function getConnectionParams(config) {
|
|
|
183
183
|
: new client_common_1.DefaultLogger(), config.log?.level),
|
|
184
184
|
};
|
|
185
185
|
}
|
|
186
|
+
function isInsertColumnsExcept(obj) {
|
|
187
|
+
return (obj !== undefined &&
|
|
188
|
+
obj !== null &&
|
|
189
|
+
typeof obj === 'object' &&
|
|
190
|
+
// Avoiding ESLint no-prototype-builtins error
|
|
191
|
+
Object.prototype.hasOwnProperty.call(obj, 'except'));
|
|
192
|
+
}
|
|
193
|
+
function getInsertQuery(params, format) {
|
|
194
|
+
let columnsPart = '';
|
|
195
|
+
if (params.columns !== undefined) {
|
|
196
|
+
if (Array.isArray(params.columns) && params.columns.length > 0) {
|
|
197
|
+
columnsPart = ` (${params.columns.join(', ')})`;
|
|
198
|
+
}
|
|
199
|
+
else if (isInsertColumnsExcept(params.columns) &&
|
|
200
|
+
params.columns.except.length > 0) {
|
|
201
|
+
columnsPart = ` (* EXCEPT (${params.columns.except.join(', ')}))`;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return `INSERT INTO ${params.table.trim()}${columnsPart} FORMAT ${format}`;
|
|
205
|
+
}
|
|
186
206
|
//# sourceMappingURL=client.js.map
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../packages/client-common/src/client.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../packages/client-common/src/client.ts"],"names":[],"mappings":";;;AAUA,6DAIkC;AA2JlC,MAAa,gBAAgB;IAQ3B,YAAY,MAA6C;QAPzD;;;;;WAAmD;QACnD;;;;;WAA+C;QAC/C;;;;;WAAqD;QACrD;;;;;WAAqD;QACrD;;;;;WAAiD;QACjD;;;;;WAAmC;QAGjC,IAAI,CAAC,gBAAgB,GAAG,mBAAmB,CAAC,MAAM,CAAC,CAAA;QACnD,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,UAAU,CAAA;QAClC,wBAAwB,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAA;QAC/C,IAAI,CAAC,UAAU,GAA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AChC;YACA,WAAW,GAAG,eAAe,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAA;SAClE;KACF;IACD,OAAO,eAAe,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,GAAG,WAAW,WAAW,MAAM,EAAE,CAAA;AAC5E,CAAC"}
|
package/dist/connection.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { WithClickHouseSummary } from './clickhouse_types';
|
|
1
2
|
import type { LogWriter } from './logger';
|
|
2
3
|
import type { ClickHouseSettings } from './settings';
|
|
3
4
|
export interface ConnectionParams {
|
|
@@ -33,8 +34,8 @@ export interface ConnQueryResult<Stream> extends ConnBaseResult {
|
|
|
33
34
|
stream: Stream;
|
|
34
35
|
query_id: string;
|
|
35
36
|
}
|
|
36
|
-
export type ConnInsertResult = ConnBaseResult;
|
|
37
|
-
export type ConnExecResult<Stream> = ConnQueryResult<Stream
|
|
37
|
+
export type ConnInsertResult = ConnBaseResult & WithClickHouseSummary;
|
|
38
|
+
export type ConnExecResult<Stream> = ConnQueryResult<Stream> & WithClickHouseSummary;
|
|
38
39
|
export type ConnPingResult = {
|
|
39
40
|
success: true;
|
|
40
41
|
} | {
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export type { Row, BaseResultSet } from './result';
|
|
|
4
4
|
export { type DataFormat } from './data_formatter';
|
|
5
5
|
export { ClickHouseError } from './error';
|
|
6
6
|
export { ClickHouseLogLevel, type ErrorLogParams, type Logger, type LogParams, } from './logger';
|
|
7
|
-
export type { ResponseJSON, InputJSON, InputJSONObjectEachRow, } from './clickhouse_types';
|
|
7
|
+
export type { ClickHouseSummary, WithClickHouseSummary, ResponseJSON, InputJSON, InputJSONObjectEachRow, } from './clickhouse_types';
|
|
8
8
|
export { type ClickHouseSettings, type MergeTreeSettings, SettingsMap, } from './settings';
|
|
9
9
|
/** For implementations usage only */
|
|
10
10
|
export { encodeJSON, isSupportedRawFormat, decode, validateStreamFormat, } from './data_formatter';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../packages/client-common/src/index.ts"],"names":[],"mappings":";;;AAAA,kDAAkD;AAClD,mCAciB;AANf,0GAAA,gBAAgB,OAAA;AASlB,iCAAyC;AAAhC,wGAAA,eAAe,OAAA;AACxB,mCAKiB;AAJf,4GAAA,kBAAkB,OAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../packages/client-common/src/index.ts"],"names":[],"mappings":";;;AAAA,kDAAkD;AAClD,mCAciB;AANf,0GAAA,gBAAgB,OAAA;AASlB,iCAAyC;AAAhC,wGAAA,eAAe,OAAA;AACxB,mCAKiB;AAJf,4GAAA,kBAAkB,OAAA;AAYpB,uCAImB;AADjB,uGAAA,WAAW,OAAA;AAGb,qCAAqC;AACrC,mDAKyB;AAJvB,4GAAA,UAAU,OAAA;AACV,sHAAA,oBAAoB,OAAA;AACpB,wGAAA,MAAM,OAAA;AACN,sHAAA,oBAAoB,OAAA;AAOtB,iCAMgB;AALd,+GAAA,sBAAsB,OAAA;AACtB,6GAAA,oBAAoB,OAAA;AACpB,uGAAA,cAAc,OAAA;AACd,qGAAA,YAAY,OAAA;AACZ,yGAAA,gBAAgB,OAAA;AAElB,mCAAmD;AAA1C,mGAAA,SAAS,OAAA;AAAE,uGAAA,aAAa,OAAA;AACjC,iCAAoC;AAA3B,mGAAA,UAAU,OAAA;AAYnB,mDAKyB;AAFvB,qHAAA,mBAAmB,OAAA;AACnB,mHAAA,iBAAiB,OAAA"}
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "0.2.
|
|
1
|
+
declare const _default: "0.2.8";
|
|
2
2
|
export default _default;
|
package/dist/version.js
CHANGED
package/package.json
CHANGED