-
Notifications
You must be signed in to change notification settings - Fork 0
/
database.js
50 lines (43 loc) · 1.3 KB
/
database.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
//constants
const sqlite3 = require('sqlite3').verbose();
const path = require('path');
const dbPath = path.join(__dirname, 'database.db');
//create database
const db = new sqlite3.Database(dbPath, sqlite3.OPEN_READWRITE | sqlite3.OPEN_CREATE, (err) => {
if (err) {
console.error(err.message);
throw err;
} else {
console.log('Connected to the SQLite database.');
}
});
module.exports = db;
//init db tables
db.serialize(() => {
db.run(`CREATE TABLE IF NOT EXISTS Admin (
AId INTEGER PRIMARY KEY,
Username TEXT NOT NULL UNIQUE,
Password TEXT NOT NULL
)`);
db.run(`CREATE TABLE IF NOT EXISTS GuestUser (
GUId INTEGER PRIMARY KEY,
Username TEXT NOT NULL UNIQUE,
Password TEXT NOT NULL
)`);
db.run(`CREATE TABLE IF NOT EXISTS Feedback (
FId INTEGER PRIMARY KEY,
Text TEXT NOT NULL,
Timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
)`);
db.run(`CREATE TABLE IF NOT EXISTS Historical_Data (
HId INTEGER PRIMARY KEY,
Date TEXT NOT NULL,
Temperature FLOAT,
Wind_Chill INTEGER,
Visibility FLOAT,
Rain FLOAT,
Snow FLOAT,
Snow_On_Ground INTEGER,
Outcome INTEGER NOT NULL
)`);
});