generated from container/tmpl
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
1.0 KiB
36 lines
1.0 KiB
/**
|
|
* 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);
|
|
}
|
|
}
|
|
};
|
|
|