npm install @prxm/clickhouse
const clickhouse = require('@prxm/clickhouse');
const config = {
host: 'localhost',
protocol: 'http',
user: 'default',
password: 'password',
};
const client = clickhouse(config);
(async () => {
await client.open();
const res = await client.selectJson('SELECT number FROM system.numbers LIMIT 10;');
console.log(res);
await client.close();
})();
The clickhouse client exposes several internal methods for usage
Send an async query to the HTTP interface.
SQL query statement.
const res = await client.query(`SELECT * FROM foo WHERE a=? AND b=?`, ['hello', 'world']);
console.log(res.data, res.meta);
Used for passing params to the query as
client.query(`SELECT * FROM foo WHERE a=? AND b=?`, ['hello', 'world']);
Used as a unique queryId
for the query.
client.query(`SELECT * FROM foo;`, [], 'xxx');
Sends an async JSON query to the HTTP interface.
SQL query statement.
Used for passing params to the query as
client.selectJson(`SELECT * FROM foo WHERE a=? AND b=?`, ['hello', 'world']);
Used as a unique queryId
for the query.
client.selectJson(`SELECT * FROM foo;`, [], 'xxx');
Batch instert for tables.
The table's name.
The items to insert, keys are used as the corresponding column names.
const items = [
{a: 1, b: 'foo', c: 3},
{a: 1, b: 'baz', c: 3},
];
client.insertBatch({ table: 'batch',items});
Used as a unique queryId
for the query.
client.insertBatch({ table: 'batch',items}, 'xxx')