Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions W3-AMT/W3-AMT/config/database.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const Sqlite3 = require('sqlite3').verbose()
const DBFILENAME = "db.sqlite"
const db = new Sqlite3.Database(DBFILENAME,(err)=>{
if(err){
console.log(err.message)
throw 'failed to connect or create DataBase'
}else{
db.run(`CREATE TABLE IF NOT EXISTS users(
user_id INTEGER PRIMARY KEY,
username TEXT NOT NULL UNIQUE,
password TEXT
)`);
db.run(`CREATE TABLE IF NOT EXISTS question(
question_id INTEGER PRIMARY KEY,
content TEXT,
category TEXT,
d TEXT,
a TEXT,
b TEXT,
c TEXT,
right TEXT NOT NULL
)`);
db.run(`CREATE TABLE IF NOT EXISTS azmon(
azmon_num INTEGER PRIMARY KEY,
user INTEGER NOT NULL,
sitution INTEGER CHECK (sitution IN (0,1)),
precent INTEGER,
FOREIGN KEY (user)
REFERENCES users (user_id)
)`);
db.run(`CREATE TABLE IF NOT EXISTS azmonitem(
id INTEGER PRIMARY KEY,
azmon_id INTEGER NOT NULL UNIQUE,
question_id INTEGER NOT NULL UNIQUE,
answer TEXT,
FOREIGN KEY (question_id)
REFERENCES question (question_id)
)`);
}
});

module.exports = db;
Loading