0.6.1 • Published 8 months ago

@prxm/clickhouse v0.6.1

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

@prxm/clickhouse : A dead simple Clickhouse client

Installation

npm install @prxm/clickhouse

Usage

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();
})();

API

The clickhouse client exposes several internal methods for usage

client.query(query, ?[params], ?queryId): Promise

Send an async query to the HTTP interface.

query: string

SQL query statement.

const res = await client.query(`SELECT * FROM foo WHERE a=? AND b=?`, ['hello', 'world']);
console.log(res.data, res.meta);
params: sqlstring params

Used for passing params to the query as

client.query(`SELECT * FROM foo WHERE a=? AND b=?`, ['hello', 'world']);
queryId: string

Used as a unique queryId for the query.

client.query(`SELECT * FROM foo;`, [], 'xxx');

client.selectJson(query, [params], ?queryId): Promise<JSON>

Sends an async JSON query to the HTTP interface.

query: string

SQL query statement.

params: sqlstring params

Used for passing params to the query as

client.selectJson(`SELECT * FROM foo WHERE a=? AND b=?`, ['hello', 'world']);
queryId: string

Used as a unique queryId for the query.

client.selectJson(`SELECT * FROM foo;`, [], 'xxx');

client.insertBatch({table, items}, ?queryId): Promise

Batch instert for tables.

{table: string}

The table's name.

{items: [{}]}

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});
queryId: string

Used as a unique queryId for the query.

client.insertBatch({ table: 'batch',items}, 'xxx')
0.4.9

1 year ago

0.5.0

8 months ago

0.6.1

8 months ago

0.6.0

8 months ago

0.5.1

8 months ago

0.4.8

2 years ago

0.4.7

2 years ago

0.4.5

2 years ago

0.4.4

2 years ago

0.4.6

2 years ago

0.4.1

2 years ago

0.4.0

2 years ago

0.4.3

2 years ago

0.4.2

2 years ago

0.3.0

2 years ago

0.2.6

2 years ago

0.1.0

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.2.3

3 years ago

0.2.2

3 years ago

0.2.5

3 years ago

0.2.4

3 years ago

0.0.1

3 years ago