-
Notifications
You must be signed in to change notification settings - Fork 0
/
index
38 lines (34 loc) · 1.14 KB
/
index
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const mysql = require('mysql');
const ClickHouse = require('@apla/clickhouse');
// MySQL connection configuration
const mysqlConfig = {
host: 'localhost',
user: '',
password: '',
database: ''
};
// ClickHouse connection configuration
const clickhouseConfig = {
host: 'localhost',
port: 8123,
user: '',
password: ''
};
// Create MySQL connection
const mysqlConnection = mysql.createConnection(mysqlConfig);
// Create ClickHouse connection
const clickhouseConnection = new ClickHouse(clickhouseConfig);
// Function to fetch data from MySQL and insert into ClickHouse using streams
(function syncData() {
mysqlConnection.connect(function(err) {
if (err) {
console.error('Error connecting to MySQL:', err);
return;
}
console.log('Connected to MySQL.');
const mysqlQuery = 'SELECT title, userId FROM test_mysql_ch';
const mysqlStream = mysqlConnection.query(mysqlQuery).stream();
const writableClickhouseStream= clickhouseConnection.query('INSERT INTO mysqlToCh', { format: 'JSONEachRow' });
mysqlStream.pipe(writableClickhouseStream);
});
})();