31 lines
967 B
TypeScript
31 lines
967 B
TypeScript
import { createClient } from '@clickhouse/client';
|
|
import config from '../config';
|
|
|
|
// Create ClickHouse client with error handling
|
|
const createClickHouseClient = () => {
|
|
try {
|
|
return createClient({
|
|
host: `http://${config.clickhouse.host}:${config.clickhouse.port}`,
|
|
username: config.clickhouse.user,
|
|
password: config.clickhouse.password,
|
|
database: config.clickhouse.database,
|
|
});
|
|
} catch (error) {
|
|
console.error('Error creating ClickHouse client:', error);
|
|
// Return a mock client for development that logs operations instead of executing them
|
|
return {
|
|
query: async ({ query, values }: { query: string; values?: any[] }) => {
|
|
console.log('ClickHouse query (mock):', query, values);
|
|
return { rows: [] };
|
|
},
|
|
close: async () => {
|
|
console.log('ClickHouse connection closed (mock)');
|
|
}
|
|
};
|
|
}
|
|
};
|
|
|
|
const clickhouse = createClickHouseClient();
|
|
|
|
|
|
export default clickhouse;
|