-
Notifications
You must be signed in to change notification settings - Fork 0
/
databaseChecker.js
40 lines (34 loc) · 1.34 KB
/
databaseChecker.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
const sqlite3 = require('sqlite3').verbose();
exports.checkDatabases = () => {
/* Database Connection */
const db = new sqlite3.cached.Database('./data/database', err => {
if (err === null) {
console.log("\nDatabase Connection successfull")
} else {
console.error("\nError - Database Connection")
}
});
/* Check if privacyShield database table exits and creates it */
db.get("SELECT name FROM sqlite_master WHERE type='table' AND name='privacy_shield'", (err, row) => {
if (!row) {
console.log("--> PrivacyShield Database created!")
db.run("CREATE TABLE privacy_shield (mac TEXT PRIMARY KEY, timestamp INTEGER, ip TEXT, blocked INTEGER DEFAULT 0, name TEXT)", err => {
if (err) {
console.error(err);
}
});
} else {
console.log("--> PrivacyShield Database found!")
}
});
/* Check if privacyTraffic database table exits */
db.get("SELECT name FROM sqlite_master WHERE type='table' AND name='privacy_traffic'", (err, row) => {
if (!row) {
console.error("--> PrivacyTraffic Database missing!")
db.close();
process.exit();
} else {
console.log("--> PrivacyTraffic Database found!")
}
});
}