import { createClient } from '@clickhouse/client'; // Create configuration object using the URL approach const config = { url: process.env.CLICKHOUSE_URL || 'http://localhost:8123', username: process.env.CLICKHOUSE_USER || 'default', password: process.env.CLICKHOUSE_PASSWORD || '', database: process.env.CLICKHOUSE_DATABASE || 'limq' }; // Log configuration (removing password for security) console.log('ClickHouse config:', { ...config, password: config.password ? '****' : '' }); // Create ClickHouse client with proper URL format export const clickhouse = createClient(config); // Log connection status console.log('ClickHouse client created with URL:', config.url); /** * Execute ClickHouse query and return results */ export async function executeQuery(query: string): Promise { try { const result = await clickhouse.query({ query, format: 'JSONEachRow', }); const data = await result.json(); return data as T[]; } catch (error) { console.error('ClickHouse query error:', error); throw error; } } /** * Execute ClickHouse query and return a single result */ export async function executeQuerySingle(query: string): Promise { const results = await executeQuery(query); return results.length > 0 ? results[0] : null; }