-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateDB.js
More file actions
37 lines (32 loc) · 1.29 KB
/
createDB.js
File metadata and controls
37 lines (32 loc) · 1.29 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
// Globals
const sqlite3 = require("sqlite3").verbose(); // use sqlite
const fs = require("fs"); // file system
const dbFileName = "Flashcards.db";
// makes the object that represents the database in our code
const db = new sqlite3.Database(dbFileName); // object, not database.
// Initialize table.
// If the table already exists, causes an error.
// Fix the error by removing or renaming Flashcards.db
//CREATE TABLE flashcards (user INT, english TEXT, korean TEXT, seen INT, correct INT )
const cmdStr = 'CREATE TABLE Flashcards (user INT, english TEXT, chinese TEXT, seen INT, correct INT, score INT)'
db.run(cmdStr,tableCreationCallback);
const cmdStr2 = 'CREATE TABLE Users (firstName TEXT, lastName TEXT, GoogleID INT )'//first name, last name, and Google ID
db.run(cmdStr2,tableCreationCallback2);
// Always use the callback for database operations and print out any
// error messages you get.
// This database stuff is hard to debug, give yourself a fighting chance.
function tableCreationCallback(err) {
if (err) {
console.log("Table creation error",err);
} else {
console.log("Database created");
}
}
function tableCreationCallback2(err) {
if (err) {
console.log("Table2 creation error",err);
} else {
console.log("Database2 created");
db.close();
}
}