> hypequery

Connecting to ClickHouse

Learn how to connect to ClickHouse databases with hypequery

Connecting to ClickHouse

hypequery provides a type-safe way to connect to ClickHouse from Node.js and browser-capable runtimes.

Run npx hypequery init to scaffold your ClickHouse connection, env variables, and schema generation so you can skip the manual setup steps below.

Connection Setup

For Node.js environments, hypequery can use the Node.js ClickHouse client automatically:

import { createQueryBuilder } from '@hypequery/clickhouse';

const db = createQueryBuilder({
  host: 'http://localhost:8123',
  username: 'default',
  password: 'password',
  database: 'my_database'
});

Client Selection:

  • In Node.js, hypequery can use @clickhouse/client automatically
  • In browser or universal setups, pass an explicit @clickhouse/client-web client

Requirements:

  • Node.js usage requires @clickhouse/client
  • Browser or universal usage requires @clickhouse/client-web and explicit client injection

Browser / universal setup

import { createQueryBuilder } from '@hypequery/clickhouse';
import { createClient } from '@clickhouse/client-web';

const client = createClient({
  host: 'https://your-clickhouse-host',
  username: 'default',
  password: '',
  database: 'my_database'
});

const db = createQueryBuilder({
  client,
});

Connection Options

hypequery supports all connection options provided by the official ClickHouse JavaScript client with full type safety:

Core Connection Options

OptionTypeDescriptionDefault
hoststringThe URL of the ClickHouse server, including protocol and portRequired
usernamestringUsername for authentication'default'
passwordstringPassword for authenticationundefined
databasestringThe database to connect to'default'

Advanced Options

OptionTypeDescription
http_headersRecord<string, string>Custom HTTP headers to include with each request
request_timeoutnumberRequest timeout in milliseconds
compression{ response?: boolean; request?: boolean }Enable compression for requests and/or responses
applicationstringApplication name to identify in ClickHouse server logs
keep_alive{ enabled: boolean }Keep-alive connection settings
loganyLogger configuration
clickhouse_settingsClickHouseSettingsAdditional ClickHouse-specific settings

References and Resources

hypequery's connection options are fully compatible with the official ClickHouse JavaScript client. Our connection implementation provides enhanced type safety and intelligent client selection while maintaining full compatibility.

For additional details on ClickHouse connection options, refer to:

On this page