-
Notifications
You must be signed in to change notification settings - Fork 0
/
connection.js
53 lines (47 loc) · 1.25 KB
/
connection.js
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const mysql = require('mysql');
const queries = require('./tables');
let connection = mysql.createConnection({
host: "remotemysql.com",
user: "iYgECwNZCY",
password: "I9VuKhVHse",
database: "iYgECwNZCY"
});
// let connection = mysql.createConnection({
// host: "localhost",
// user: "root",
// password: "",
// database: "InternetTimeline"
// });
connection.connect((err) => {
if (err) {
console.log('Database not connected');
} else {
queries.map((query, i) => {
// , (err, result) => {
// if (err) console.log(`Table ${i} :-\n${err}`);
// else console.log(`Table ${i} :-\n${result}`);
// }
connection.query(query)
if (i === queries.length - 1) {
console.log('Database connected...\n');
}
})
}
})
function handleConnection() {
setInterval(() => {
console.log(`>>>>> Handeling connection <<<<<\n`);
connection.query(`SELECT * FROM USERS`, (err, result) => {
if (err) {
console.log(`Invaild query\nConnection can get terminated\n`);
} else {
console.log(`Connection handled\n`);
// console.log(`Result of query :-\n`);
// console.log(result);
// console.log(`\n----------------------------------------\n`);
}
})
}, 1000 * 60 * 4)
}
handleConnection();
module.exports = connection;