
连接 clickhouse 数据库
在 vue 项目中使用 clickhouse js 进行连接数据库的步骤如下:
1. 引入依赖
npm install clickhouse-js
2. 封装数据库连接
立即学习“前端免费学习笔记(深入)”;
import { client } from 'clickhouse-js';
const client = new client({
host: 'localhost',
port: 8123,
user: 'default',
password: '',
});3. 查询数据库
const query = 'select * from table';
client.query(query).then(result => {
console.log(result);
});4. 增删改查
// 插入数据 const insertQuery = 'INSERT INTO table (name, age) VALUES (?, ?)'; client.insert(insertQuery, ['John', 30]); // 更新数据 const updateQuery = 'UPDATE table SET age = ? WHERE name = ?'; client.update(updateQuery, [31, 'John']); // 删除数据 const deleteQuery = 'DELETE FROM table WHERE name = ?'; client.delete(deleteQuery, ['John']);










