@clickhouse/client 0.0.5 → 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 +22 -21
- package/dist/clickhouse_types.d.ts +9 -2
- package/dist/client.d.ts +16 -3
- package/dist/client.js +15 -4
- package/dist/client.js.map +1 -1
- package/dist/data_formatter/formatter.d.ts +1 -1
- package/dist/data_formatter/formatter.js +7 -3
- package/dist/data_formatter/formatter.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -150,27 +150,28 @@ See also:
|
|
|
150
150
|
|
|
151
151
|
## Supported formats
|
|
152
152
|
|
|
153
|
-
| Format | Input (array) | Input (stream) | Output (JSON) | Output (text) |
|
|
154
|
-
| ------------------------------------------ | ------------- | -------------- | ------------- | ------------- |
|
|
155
|
-
| JSON | ❌ | ❌ | ✔️ | ✔️ |
|
|
156
|
-
|
|
|
157
|
-
|
|
|
158
|
-
|
|
|
159
|
-
|
|
|
160
|
-
|
|
|
161
|
-
|
|
|
162
|
-
|
|
|
163
|
-
|
|
|
164
|
-
|
|
|
165
|
-
|
|
|
166
|
-
|
|
|
167
|
-
|
|
|
168
|
-
|
|
|
169
|
-
|
|
|
170
|
-
|
|
|
171
|
-
|
|
|
172
|
-
|
|
|
173
|
-
|
|
|
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 | ❌ | ✔️ | ❌ | ❌ | ✔️ |
|
|
174
175
|
|
|
175
176
|
The entire list of ClickHouse input and output formats is available [here](https://clickhouse.com/docs/en/interfaces/formats).
|
|
176
177
|
|
|
@@ -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:
|
|
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
|
@@ -4,10 +4,11 @@ import { Logger } from './logger';
|
|
|
4
4
|
import { type DataFormat } from './data_formatter';
|
|
5
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 {
|
|
8
9
|
/** A ClickHouse instance URL. Default value: `http://localhost:8123`. */
|
|
9
10
|
host?: string;
|
|
10
|
-
/** The timeout to
|
|
11
|
+
/** The timeout to set up a connection in milliseconds. Default value: `10_000`. */
|
|
11
12
|
connect_timeout?: number;
|
|
12
13
|
/** The request timeout in milliseconds. Default value: `30_000`. */
|
|
13
14
|
request_timeout?: number;
|
|
@@ -54,11 +55,12 @@ export interface ExecParams extends BaseParams {
|
|
|
54
55
|
/** Statement to execute. */
|
|
55
56
|
query: string;
|
|
56
57
|
}
|
|
58
|
+
declare type InsertValues<T> = ReadonlyArray<T> | Stream.Readable | InputJSON<T> | InputJSONObjectEachRow<T>;
|
|
57
59
|
export interface InsertParams<T = unknown> extends BaseParams {
|
|
58
60
|
/** Name of a table to insert into. */
|
|
59
61
|
table: string;
|
|
60
62
|
/** A dataset to insert. */
|
|
61
|
-
values:
|
|
63
|
+
values: InsertValues<T>;
|
|
62
64
|
/** Format of the dataset to insert. */
|
|
63
65
|
format?: DataFormat;
|
|
64
66
|
}
|
|
@@ -74,5 +76,16 @@ export declare class ClickHouseClient {
|
|
|
74
76
|
ping(): Promise<boolean>;
|
|
75
77
|
close(): Promise<void>;
|
|
76
78
|
}
|
|
77
|
-
export declare function validateInsertValues(values:
|
|
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;
|
|
78
90
|
export declare function createClient(config?: ClickHouseClientConfigOptions): ClickHouseClient;
|
|
91
|
+
export {};
|
package/dist/client.js
CHANGED
|
@@ -3,7 +3,7 @@ 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");
|
|
@@ -132,8 +132,11 @@ function removeSemi(query) {
|
|
|
132
132
|
return query;
|
|
133
133
|
}
|
|
134
134
|
function validateInsertValues(values, format) {
|
|
135
|
-
if (Array.isArray(values)
|
|
136
|
-
|
|
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
|
-
|
|
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
|
}
|
package/dist/client.js.map
CHANGED
|
@@ -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,qC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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"}
|
|
@@ -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 = [
|
|
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(`
|
|
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 (
|
|
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,
|
|
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;IAC3B,MAAM;IACN,mBAAmB;IACnB,GAAG,qBAAqB;CAChB,CAAA;AACV,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,QAAQ,CAAC,UAAU,CAAC,CAAA;AACxE,CAAC;AAFD,oDAEC;AAED,SAAgB,oBAAoB,CAClC,MAAW;IAEX,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;QACtC,MAAM,IAAI,KAAK,CACb,GAAG,MAAM,kDAAkD,gBAAgB,CAAC,IAAI,CAC9E,GAAG,CACJ,EAAE,CACJ,CAAA;KACF;IACD,OAAO,IAAI,CAAA;AACb,CAAC;AAXD,oDAWC;AAED;;;;GAIG;AACH,SAAgB,MAAM,CAAC,IAAY,EAAE,MAAkB;IACrD,IAAI,MAAM,KAAK,MAAM,EAAE;QACrB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;KACxB;IACD,IAAI,sBAAsB,CAAC,MAAM,CAAC,EAAE;QAClC,OAAO,IAAI;aACR,KAAK,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
|
@@ -10,6 +10,6 @@ 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,
|
|
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.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,mCAAyC;AAA3B,mGAAA,SAAS,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"}
|