ai-query对接新版freesun-agent接口的分支
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.
 
 
 

38 lines
1.2 KiB

'use strict';
const { createClient } = require('@clickhouse/client');
module.exports = (app, conf) => {
if (conf.clickHouse) {
try {
app.fs = app.fs || {};
app.fs.clickHouse = {};
// 移除 debug,只保留必要的配置
const { url, user, password, db = [] } = conf.clickHouse;
if (!url) {
throw new Error('CLICKHOUST_URL (完整 URL) is required! e.g., http://127.0.0.1:8123');
}
for (let d of db) {
if (d.name && d.db) {
app.fs.clickHouse[d.name] = createClient({
url: url,
username: user,
password: password,
database: d.db,
// 调试日志通过环境变量 NODE_DEBUG=clickhouse 控制
});
console.info(`ClickHouse ${d.name} 初始化完成`);
} else {
throw new Error(`conf.clickHouse 参数错误!db 配置必须包含 name 和 db: ${JSON.stringify(d)}`);
}
}
} catch (error) {
console.error('初始化 ClickHouse 客户端失败:', error);
process.exit(-1);
}
}
};