File size: 1,644 Bytes
bd72e7f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
const sqlite3 = require('sqlite3').verbose();
const db = new sqlite3.Database('./database.sqlite');

db.serialize(() => {
  // Create Tables
  db.run(`CREATE TABLE IF NOT EXISTS sampleStudent (

    id INTEGER PRIMARY KEY AUTOINCREMENT,

    name TEXT,

    subject1 INTEGER,

    subject2 INTEGER,

    subject3 INTEGER

  )`);

  db.run(`CREATE TABLE IF NOT EXISTS grade_rules (

    id INTEGER PRIMARY KEY AUTOINCREMENT,

    min_avg INTEGER,

    max_avg INTEGER,

    grade TEXT

  )`);

  db.run(`CREATE TABLE IF NOT EXISTS personality_traits (

    id INTEGER PRIMARY KEY AUTOINCREMENT,

    grade TEXT,

    trait TEXT

  )`);

  // Seed Data (Check if exists first to avoid duplicates on re-run, or just delete file)
  // For simplicity in this script, we'll clear and re-insert logic tables
  db.run(`DELETE FROM grade_rules`);
  const gradeStmt = db.prepare("INSERT INTO grade_rules (min_avg, max_avg, grade) VALUES (?, ?, ?)");
  gradeStmt.run(90, 100, 'A');
  gradeStmt.run(75, 89, 'B');
  gradeStmt.run(60, 74, 'C');
  gradeStmt.run(40, 59, 'D');
  gradeStmt.run(0, 39, 'E');
  gradeStmt.finalize();

  db.run(`DELETE FROM personality_traits`);
  const traitStmt = db.prepare("INSERT INTO personality_traits (grade, trait) VALUES (?, ?)");
  traitStmt.run('A', 'Highly Disciplined & Leader');
  traitStmt.run('B', 'Confident & Responsible');
  traitStmt.run('C', 'Hardworking & Consistent');
  traitStmt.run('D', 'Needs Motivation');
  traitStmt.run('E', 'Requires Improvement');
  traitStmt.finalize();

  console.log("SQLite Database initialized with tables and seed data.");
});

db.close();