-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.js
More file actions
143 lines (130 loc) · 4.02 KB
/
database.js
File metadata and controls
143 lines (130 loc) · 4.02 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
const sqlite3 = require('sqlite3').verbose();
const db = new sqlite3.Database('./learning_platform.db');
db.serialize(() => {
db.run(`
CREATE TABLE IF NOT EXISTS courses (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
instructor TEXT NOT NULL,
duration TEXT
)
`);
db.run(`
CREATE TABLE IF NOT EXISTS instructors (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
bio TEXT,
subjects TEXT,
contact TEXT,
image_url TEXT
)
`);
db.run(`
CREATE TABLE IF NOT EXISTS events (
id INTEGER PRIMARY KEY AUTOINCREMENT,
title TEXT NOT NULL,
description TEXT,
schedule TEXT NOT NULL
)
`);
db.run(`
CREATE TABLE IF NOT EXISTS faqs (
id INTEGER PRIMARY KEY AUTOINCREMENT,
question TEXT NOT NULL,
answer TEXT NOT NULL
)
`);
db.run(`
CREATE TABLE IF NOT EXISTS contact_submissions (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
email TEXT NOT NULL,
message TEXT NOT NULL,
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
)
`);
const instructorsToInsert = [
{
name: 'Prof John Erasmus',
bio: 'CompTIA guru with extensive experience in IT certifications.',
subjects: 'CompTIA A+, Network+, Security+',
contact: 'john.erasmus@techgrow.ac.uk',
image_url: '/img/john_erasmus.jpg'
},
{
name: 'Prof David Turing',
bio: 'Cisco and network expert, passionate about sharing knowledge.',
subjects: 'CCNA, CCNP, Network Automation',
contact: 'david.turing@techgrow.ac.uk',
image_url: '/img/david_turing.jpg'
},
{
name: 'Prof Sarah Brightman',
bio: 'Expert in Network Security and cyber awareness.',
subjects: 'Network Security Foundation',
contact: 'sarah.brightman@techgrow.ac.uk',
image_url: '/img/sarah_brightman.jpg'
}
];
instructorsToInsert.forEach(instructor => {
db.get('SELECT id FROM instructors WHERE name = ?', [instructor.name], (err, row) => {
if (err) return console.error(err.message);
if (!row) {
db.run(`
INSERT INTO instructors (name, bio, subjects, contact, image_url)
VALUES (?, ?, ?, ?, ?)
`, [instructor.name, instructor.bio, instructor.subjects, instructor.contact, instructor.image_url]);
}
});
});
const eventsToInsert = [
{
title: 'Live Q&A with Prof John Erasmus',
description: 'Ask questions about CompTIA certifications.',
schedule: 'Every Monday at 6 PM'
},
{
title: 'Grow with us Bonus Seminar: My SQL or MongoDB?',
description: 'Explore the differences between relational and NoSQL databases with Prof David Turing.',
schedule: '15th March 2025 at 2 PM'
},
{
title: 'Network Security Insights with Sarah Brightman',
description: 'Join Sarah Brightman for a comprehensive overview of foundational network security principles.',
schedule: '28th June 2025 at 3 PM'
}
];
eventsToInsert.forEach(event => {
db.get('SELECT id FROM events WHERE title = ?', [event.title], (err, row) => {
if (err) return console.error(err.message);
if (!row) {
db.run(`
INSERT INTO events (title, description, schedule)
VALUES (?, ?, ?)
`, [event.title, event.description, event.schedule]);
}
});
});
const faqsToInsert = [
{
question: 'What are the instructor qualifications?',
answer: 'Our instructors are industry experts with years of experience.'
},
{
question: 'How do I contact instructors?',
answer: 'Contact details are available on their profile pages.'
}
];
faqsToInsert.forEach(faq => {
db.get('SELECT id FROM faqs WHERE question = ?', [faq.question], (err, row) => {
if (err) return console.error(err.message);
if (!row) {
db.run(`
INSERT INTO faqs (question, answer)
VALUES (?, ?)
`, [faq.question, faq.answer]);
}
});
});
});
module.exports = db;