npm i @clickhouse/client
import { createClient } from '@clickhouse/client'
const client = createClient({
host: `https://<host>:8443`,
password: '<password>',
})
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,
},
})
await client.insert({
table: 'clickhouse_js_example_table',
values: [
{ id: 42, name: 'foo' },
{ id: 42, name: 'bar' },
],
format: 'JSONEachRow',
})
const rows = await client.query({
query: 'SELECT * FROM clickhouse_js_example_table',
format: 'JSONEachRow',
})
console.log(await rows.json())