Skip to main content

ClickHouse

ClickHouse is an open-source, high performance columnar OLAP database management system for real-time analytics using SQL.

Official Websitehttps://clickhouse.com/
TagsDatabaseSQL
Network Connection needs

This integration needs network access to the server where the service is running.

See the Network access page for details about how to achieve that.

Credential configuration

Fill in the appropiate values for your ClickHouse connection. Specify the required fields: host, database, username and password.

In the extra options field, you can include any of the parameter found here.

Here is an example of a filled credential configuration form in YepCode:

ClickHouse Snippets available in YepCode editor

note

The title is the triggering text for YepCode to autocomplete the script.

Integration

New integration from credential
const clickhouse = yepcode.integration.clickhouse('credential-slug')
New integration from plain authentication data
const { createClient } = require('@clickhouse/client')

const clickhouse = createClient({
host: 'https://play-api.clickhouse.com:8123',
username: 'playground',
password: 'clickhouse',
database: 'my_database_name'
})

Execute Query

Execute query (promise)
const resultSet = await clickhouse.query({
query: 'SELECT * FROM my_table',
format: 'JSONEachRow',
})
const dataset = await resultSet.json()
console.log(dataset);
Execute query (stream)
const resultSet = await clickhouse.query({
query: 'SELECT number FROM system.numbers_mt LIMIT 5',
format: 'CSV',
})
const stream = resultSet.stream()
stream.on('data', (rows) => {
rows.forEach((row) => {
console.log(row.text)
})
})
await new Promise((resolve) => {
stream.on('end', () => {
console.log('Completed!')
resolve(0)
})
})

Insert

Insert
await clickhouse.insert({
table: 'my_table',
// structure should match the desired format, JSONEachRow in this example
values: [
{ id: 42, name: 'foo' },
{ id: 42, name: 'bar' },
],
format: 'JSONEachRow',
})