Going to re:Invent this December? Come party with us and The Chainsmokers ->->

Installation

npm i @clickhouse/client

Examples

Create an instance

import { createClient } from '@clickhouse/client'

const client = createClient({
  host: `https://<host>:8443`,
  password: '<password>',
})

Simple 'command' without a result:

await client.exec({
  query: `
    CREATE TABLE IF NOT EXISTS clickhouse_js_example_table
    (id UInt64, name String)
    ORDER BY (id)
  `,
  clickhouse_settings: {
    wait_end_of_query: 1,
  },
})

Bulk insert

await client.insert({
  table: 'clickhouse_js_example_table',
  values: [
    { id: 42, name: 'foo' },
    { id: 42, name: 'bar' },
  ],
  format: 'JSONEachRow',
})

Basic query

const rows = await client.query({
  query: 'SELECT * FROM clickhouse_js_example_table',
  format: 'JSONEachRow',
})

console.log(await rows.json())

Other integrations

Get started with ClickHouse Cloud for free

We'll get you started on a 30 day trial and $300 credits to spend at your own pace.