Skip to main content

snippets_js

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',
})