# @vulcan-sql/extension-driver-clickhouse

> Clickhouse driver for VulcanSQL

Latest version **0.10.4** (published 2024-01-18) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @vulcan-sql/extension-driver-clickhouse
pnpm add @vulcan-sql/extension-driver-clickhouse
yarn add @vulcan-sql/extension-driver-clickhouse
bun add @vulcan-sql/extension-driver-clickhouse
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.10.4 |
| Published | 2024-01-18 |
| First published | 2023-07-07 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 21 |
| Unpacked size | 38.9 KB |
| Known vulnerabilities | 0 (+25 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 792 |
| Maintainers | fredalai, shimin.wong, star.you, cannerbot, eason.kuo, wwwy3y3 |
| Keywords | vulcan, vulcan-sql, data, sql, database, data-warehouse, data-lake, api-builder, clickhouse, ch |

## Links

- npm: https://www.npmjs.com/package/@vulcan-sql/extension-driver-clickhouse
- Repository: https://github.com/Canner/vulcan
- Homepage: https://github.com/Canner/vulcan#readme
- Issues: https://github.com/Canner/vulcan/issues
- npm.io page: https://npm.io/package/@vulcan-sql/extension-driver-clickhouse

## Dependencies (21)

- [ms](https://npm.io/package/ms.md) 3.0.0-canary.1
- [joi](https://npm.io/package/joi.md) ^17.6.0
- [koa](https://npm.io/package/koa.md) ^2.13.4
- [glob](https://npm.io/package/glob.md) ^8.0.1
- [uuid](https://npm.io/package/uuid.md) ^9.0.0
- [axios](https://npm.io/package/axios.md) ^0.27.2
- [dayjs](https://npm.io/package/dayjs.md) ^1.11.2
- [tslib](https://npm.io/package/tslib.md) ^2.3.0
- [tslog](https://npm.io/package/tslog.md) ^3.3.3
- [duckdb](https://npm.io/package/duckdb.md) 0.7.1
- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [moment](https://npm.io/package/moment.md) ^2.29.4
- [js-yaml](https://npm.io/package/js-yaml.md) ^4.1.0
- [bluebird](https://npm.io/package/bluebird.md) ^3.7.2
- [nunjucks](https://npm.io/package/nunjucks.md) ^3.2.3
- [inversify](https://npm.io/package/inversify.md) ^6.0.1
- [toad-scheduler](https://npm.io/package/toad-scheduler.md) ^2.2.0
- [class-validator](https://npm.io/package/class-validator.md) ^0.14.0
- [reflect-metadata](https://npm.io/package/reflect-metadata.md) ^0.1.13
- [class-transformer](https://npm.io/package/class-transformer.md) ^0.5.1
- [@clickhouse/client](https://npm.io/package/@clickhouse/client.md) ^0.1.1

## Alternatives

- [d3-force-3d](https://npm.io/package/d3-force-3d.md) — 1.0M weekly downloads
- [ng2-charts](https://npm.io/package/ng2-charts.md) — 486.8K weekly downloads
- [@arcgis/core](https://npm.io/package/@arcgis/core.md) — 257.8K weekly downloads
- [react-sparklines](https://npm.io/package/react-sparklines.md) — 249.3K weekly downloads
- [react-native-gifted-charts](https://npm.io/package/react-native-gifted-charts.md) — 182.3K weekly downloads

## Recent versions

- 0.10.4 (latest) — 2024-01-18
- 0.10.4-dev.20240207.0 (dev) — 2024-02-07
- 0.10.4-beta.0 (beta) — 2024-01-18
- 0.10.4-dev.20240202.0 — 2024-02-02
- 0.10.4-dev.20240131.0 — 2024-01-31
- 0.10.4-dev.20240130.0 — 2024-01-30
- 0.10.4-dev.20240129.0 — 2024-01-29
- 0.10.4-dev.20240126.0 — 2024-01-26
- 0.10.4-dev.20240123.0 — 2024-01-23
- 0.10.4-dev.20240122.0 — 2024-01-22
- 0.10.3 — 2024-01-11
- 0.10.3-beta.0 — 2024-01-11
- 0.10.2 — 2023-10-24
- 0.10.2-beta.0 — 2023-10-24
- 0.10.1-dev.20231018.0 — 2023-10-18
- … 43 more at https://npm.io/package/@vulcan-sql/extension-driver-clickhouse/versions

## README

# extension-driver-clickhouse

This is the ClickHouse driver for VulcanSQL, provided by [Canner](https://canner.io/).

## Installation

1. Install the package:

   ```bash
   npm i @vulcan-sql/extension-driver-clickhouse
   ```

2. Update your `vulcan.yaml` file to enable the extension:

   ```yaml
   extensions:
     clickhouse: '@vulcan-sql/extension-driver-clickhouse'
   ```

3. Create a new profile in your `profiles.yaml` file or in the designated profile paths. For more information, please refer to the [ClickHouse Client documentation](https://clickhouse.com/docs/en/integrations/language-clients/nodejs) for the available arguments.

   ```yaml
   - name: ch # Profile name
     type: clickhouse
     connection:
       # Optional: ClickHouse instance URL. Default is http://localhost:8123.
       host: 'www.example.com:8123'
       # Optional: Request timeout in milliseconds. Default value: 30000
       request_timeout: 60000
       # Optional: Maximum number of sockets to allow per host. Default value: Infinity.
       max_open_connections: 10
       # Optional: Compression settings for data transfer. Currently, only GZIP compression using zlib is supported. See https://clickhouse.com/docs/en/integrations/language-clients/nodejs#compression for details.
       compression:
         # Optional: "response: true" instructs ClickHouse server to respond with a compressed response body. Default: true
         response: true
         # Optional: "request: true" enables compression on the client request body. Default value: false
         request: false
       # Optional: The name of the user on whose behalf requests are made. Default value for username: 'default'
       username: 'user'
       # The user's password. Default: ''.
       password: 'pass'
       # Optional: The name of the application using the Node.js client. Default value: VulcanSQL
       application: 'VulcanSQL'
       # Optional: Database name to use. Default value: 'default'
       database: 'hello-clickhouse'
       # Optional: ClickHouse settings to apply to all requests. The following is a sample configuration.
       # For all available settings, see https://clickhouse.com/docs/en/operations/settings.
       # For the definition, see https://github.com/ClickHouse/clickhouse-js/blob/0.1.1/src/settings.ts
       clickhouse_settings:
         # Optional: Allow Nullable types as primary keys. Default: false
         allow_nullable_key: true
       # Optional: Configure TLS certificates. See https://clickhouse.com/docs/en/integrations/language-clients/nodejs#tls-certificates
       tls:
         # Optional: The path to the CA Cert file
         ca_cert: 'ca-cert-file-path'
         # Optional: The path to the Cert file
         cert: 'cert-file-path'
         # Optional: The path to the key file
         key: 'key-path'
       # Optional: ClickHouse Session ID to send with every request
       session_id: ''
       # Optional: HTTP Keep-Alive related settings. See https://clickhouse.com/docs/en/integrations/language-clients/nodejs#keep-alive
       keep_alive:
         # Optional: Enable or disable HTTP Keep-Alive mechanism. Default: true
         enabled: true
         # Optional: How long to keep a particular open socket alive on the client side (in milliseconds).
         # Should be less than the server setting (see `keep_alive_timeout` in the server's `config.xml`).
         # Currently, has no effect if unset or false. Default value: 2500 (based on the default ClickHouse server setting, which is 3000)
         socket_ttl: 2500
         # Optional: If the client detects a potentially expired socket based on this value, the socket will be immediately destroyed before sending the request, and the request will be retried with a new socket up to 3 times. Default: false (no retries)
         retry_on_expired_socket: false
   ```

The `log` option is not included above because it requires defining a Logger class and assigning it. Therefore, it cannot be set through `profiles.yaml`.

## Note

ClickHouse supports parameterized queries to prevent SQL injection using prepared statements. Named placeholders are defined using the `{name:type}` syntax. For more information, refer to the [Query with Parameters](https://clickhouse.com/docs/en/integrations/language-clients/nodejs#queries-with-parameters) section in the ClickHouse documentation.

However, the VulcanSQL API supports JSON format for API query parameters and does not support the full range of types available in ClickHouse. VulcanSQL only supports the conversion of the following types:

- `boolean` to ClickHouse type `Bool`
- `number` to ClickHouse types `Int` or `Float`
- `string` to ClickHouse type `String`

Therefore, if you need to query data with special types in ClickHouse, such as `Array(Unit8)`, `Record<K, V>`, `Date`, `DateTime`, and so on, you can use ClickHouse [Regular Functions](https://clickhouse.com/docs/en/sql-reference/functions) or [Type Conversion Functions](https://clickhouse.com/docs/en/sql-reference/functions/type-conversion-functions) to handle them.

Example:

```sql
-- If the `val` from the API query parameter is '1990-11-01' and the `born_date` column is of type `Date32`,
-- you can use the toDate function to convert the value. See https://clickhouse.com/docs/en/sql-reference/functions/type-conversion-functions#todate
SELECT * FROM users WHERE born_date = toDate({val:String});
```

## ⚠️ Caution

The ClickHouse driver currently does not support caching datasets. If you use the ClickHouse driver with caching dataset features, it will result in failure.

## Testing

To run tests for the `extension-driver-clickhouse` module, use the following command:

```bash
nx test extension-driver-clickhouse
```

---
_Source: https://npm.io/package/@vulcan-sql/extension-driver-clickhouse · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
