/** * Created by Julin on 2022/11/07. */ 'use strict'; const { ClickHouse } = require('clickhouse'); module.exports = function (config) { const defaultConfig = require('../../config').clickhouse; config = config || defaultConfig; if (config) { try { const { url, port, username, password, databases = [] } = config; let clickhouse = {}; for (let db of databases) { clickhouse[db.key] = new ClickHouse({ url, port, format: 'json', basicAuth: username && password ? { username, password, } : null, config: { database: db.name } }); } process.clickhouse = clickhouse; return clickhouse; } catch (err) { process.logger.error('ClickHouse init error:', err); process.exit(1); } } };