-
Notifications
You must be signed in to change notification settings - Fork 0
/
initDB.js
33 lines (29 loc) · 879 Bytes
/
initDB.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
#!/usr/bin/env node
/* -----------------------------
MODULE
----------------------------- */
const sqlite3 = require('sqlite3').verbose()
/* -----------------------------
CONNECTION DB
----------------------------- */
let db = new sqlite3.Database('quizz.db', (err) => {
if (err){
return console.error(err.message)
}
console.log("Connected to the SQLite db !")
})
/* -----------------------------
INIT DB
----------------------------- */
db.serialize(() => {
//.run() retourne un obj Database qui permet de chainer les appels de méthode
db.run("DROP TABLE user")
db.run("CREATE TABLE user (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)")
})
//Fermeture de la BDD
db.close((err) => {
if (err){
return console.error(err.message)
}
console.log("Close the database connection !")
})