@clickhouse/client-web 1.18.1 → 1.18.2-head.59c3f62.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/utils/stream.js +20 -9
- 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 +2 -2
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/utils/stream.js
CHANGED
|
@@ -8,22 +8,33 @@ function isStream(obj) {
|
|
|
8
8
|
return (obj !== null && obj !== undefined && typeof obj.pipeThrough === 'function');
|
|
9
9
|
}
|
|
10
10
|
async function getAsText(stream) {
|
|
11
|
-
let
|
|
12
|
-
let isDone = false;
|
|
11
|
+
let text = '';
|
|
13
12
|
const textDecoder = new TextDecoder();
|
|
14
13
|
const reader = stream.getReader();
|
|
15
|
-
while (
|
|
14
|
+
while (true) {
|
|
16
15
|
const { done, value } = await reader.read();
|
|
17
16
|
const decoded = textDecoder.decode(value, { stream: true });
|
|
18
|
-
if (decoded.length +
|
|
17
|
+
if (decoded.length + text.length > MaxStringLength) {
|
|
18
|
+
// The error message is crafted to be similar to the one thrown by Node's implementation.
|
|
19
|
+
// A simple try/catch block around the concatenation of the decoded chunk would not work
|
|
20
|
+
// as different browsers throw profoundly different errors including "out of memory"
|
|
21
|
+
// in tests. Somehow using manual length checks seems to be the only way to reliably
|
|
22
|
+
// detect this condition across browsers.
|
|
23
|
+
// Also, Vitest crashes while running the try/catch implementatioin in Firefox.
|
|
19
24
|
throw new Error('The response length exceeds the maximum allowed size of V8 String: ' +
|
|
20
25
|
`${MaxStringLength}; consider limiting the amount of requested rows.`);
|
|
21
26
|
}
|
|
22
|
-
|
|
23
|
-
|
|
27
|
+
text += decoded;
|
|
28
|
+
if (done)
|
|
29
|
+
break;
|
|
24
30
|
}
|
|
25
|
-
// flush
|
|
26
|
-
|
|
27
|
-
|
|
31
|
+
// flush unfinished multi-byte characters
|
|
32
|
+
const decoded = textDecoder.decode();
|
|
33
|
+
if (decoded.length + text.length > MaxStringLength) {
|
|
34
|
+
throw new Error('The response length exceeds the maximum allowed size of V8 String: ' +
|
|
35
|
+
`${MaxStringLength}; consider limiting the amount of requested rows.`);
|
|
36
|
+
}
|
|
37
|
+
text += decoded;
|
|
38
|
+
return text;
|
|
28
39
|
}
|
|
29
40
|
//# sourceMappingURL=stream.js.map
|
package/dist/utils/stream.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../../src/utils/stream.ts"],"names":[],"mappings":";;AAGA,4BAIC;AAED,
|
|
1
|
+
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../../src/utils/stream.ts"],"names":[],"mappings":";;AAGA,4BAIC;AAED,8BAoCC;AA7CD,+EAA+E;AAC/E,MAAM,eAAe,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,EAAE,CAAA;AAE5C,SAAgB,QAAQ,CAAC,GAAQ;IAC/B,OAAO,CACL,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,SAAS,IAAI,OAAO,GAAG,CAAC,WAAW,KAAK,UAAU,CAC3E,CAAA;AACH,CAAC;AAEM,KAAK,UAAU,SAAS,CAAC,MAAsB;IACpD,IAAI,IAAI,GAAG,EAAE,CAAA;IAEb,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAA;IACrC,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,EAAE,CAAA;IAEjC,OAAO,IAAI,EAAE,CAAC;QACZ,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAA;QAC3C,MAAM,OAAO,GAAG,WAAW,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAA;QAC3D,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,GAAG,eAAe,EAAE,CAAC;YACnD,yFAAyF;YACzF,wFAAwF;YACxF,oFAAoF;YACpF,oFAAoF;YACpF,yCAAyC;YACzC,+EAA+E;YAC/E,MAAM,IAAI,KAAK,CACb,qEAAqE;gBACnE,GAAG,eAAe,mDAAmD,CACxE,CAAA;QACH,CAAC;QACD,IAAI,IAAI,OAAO,CAAA;QACf,IAAI,IAAI;YAAE,MAAK;IACjB,CAAC;IAED,yCAAyC;IACzC,MAAM,OAAO,GAAG,WAAW,CAAC,MAAM,EAAE,CAAA;IACpC,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,GAAG,eAAe,EAAE,CAAC;QACnD,MAAM,IAAI,KAAK,CACb,qEAAqE;YACnE,GAAG,eAAe,mDAAmD,CACxE,CAAA;IACH,CAAC;IACD,IAAI,IAAI,OAAO,CAAA;IAEf,OAAO,IAAI,CAAA;AACb,CAAC"}
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "1.18.1";
|
|
1
|
+
declare const _default: "1.18.2-head.59c3f62.1";
|
|
2
2
|
export default _default;
|
package/dist/version.js
CHANGED
package/dist/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":";;AAAA,kBAAe,
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":";;AAAA,kBAAe,uBAAuB,CAAA"}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@clickhouse/client-web",
|
|
3
3
|
"description": "Official JS client for ClickHouse DB - Web API implementation",
|
|
4
4
|
"homepage": "https://clickhouse.com",
|
|
5
|
-
"version": "1.18.1",
|
|
5
|
+
"version": "1.18.2-head.59c3f62.1",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"keywords": [
|
|
8
8
|
"clickhouse",
|
|
@@ -30,6 +30,6 @@
|
|
|
30
30
|
"build": "rm -rf dist; tsc"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@clickhouse/client-common": "1.18.1"
|
|
33
|
+
"@clickhouse/client-common": "1.18.2-head.59c3f62.1"
|
|
34
34
|
}
|
|
35
35
|
}
|