clickhouse
NodeJS client for ClickHouse. Send query over HTTP interface.
Install:
npm i clickhouse
Example:
const ClickHouse = ; const clickhouse = ;
or with all options:
const clickhouse = url: 'http://localhost' port: 8123 debug: false basicAuth: null isUseGzip: false format: "json" // "json" || "csv" || "tsv" config: session_id : 'session_id if neeed' session_timeout : 60 output_format_json_quote_64bit_integers : 0 enable_http_compression : 0 database : 'my_database_name' // This object merge with request params (see request lib docs) reqParams: ... ;
or change
basicAuth: null
to
basicAuth: {
username: 'default',
password: '',
},
Exec query:
const queries = 'DROP TABLE IF EXISTS session_temp' `CREATE TABLE session_temp ( date Date, time DateTime, mark String, ips Array(UInt32), queries Nested ( act String, id UInt32 ) ) ENGINE=MergeTree(date, (mark, time), 8192)` 'OPTIMIZE TABLE ukit.loadstat PARTITION 201807 FINAL'; forconst query of queries const r = await clickhouse; console;
Exec by callback way:
clickhouse;
Stream:
clickhouse ;
or async stream:
// async iterationfor await const row of clickhouse console;
As promise:
const rows = await clickhouse; // use query with external dataconst rows = await clickhouse;
Set session:
clickhousesessionId = '...';const r = await clickhouse;
In case your application requires specific sessions to manage specific data then you can send session_id
with each query.
let mySessionId = 'some_randome_string';const r = await clickhouse;
Insert stream:
const ws = clickhouse;forlet i = 0; i <= 1000; i++ await ws; //wait stream finishconst result = await ws;
Pipe readable stream to writable stream (across transform):
const rs = clickhouse; const tf = objectMode : true { ; }; clickhousesessionId = Date;const ws = clickhouse; const result = await rs;
Changelogs:
- 2020-04-17 (v2.1.0)
- Fix query with totals. For json formats work perfect, but for another - doesn't
- 2019-02-13
- Add compatibility with user and username options
- 2019-02-07
- Add TLS/SSL Protocol support
- Add async iteration over SELECT
Links
- request lib doc https://github.com/request/request#requestoptions-callback