forked from discord/discord-example-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clear_database.js
55 lines (52 loc) · 1.49 KB
/
clear_database.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/**
* Drops the users and pledges tables, and recreates them.
*/
import sqlite3 from "sqlite3";
let db = new sqlite3.Database("./db/users.db", (err) => {
if (err) {
return console.error(err.message);
}
console.log("Connected to the in-memory SQLite database.");
});
db.serialize(() => {
db.run("DROP TABLE IF EXISTS users", (err) => {
if (err) {
console.log("Failed to drop users table");
return console.error(err.message);
}
console.log("Table dropped");
})
.run("DROP TABLE IF EXISTS pledges", (err) => {
if (err) {
console.log("Failed to drop pledges table");
return console.error(err.message);
}
console.log("Table dropped");
})
.run(
"CREATE TABLE users(id INTEGER PRIMARY KEY AUTOINCREMENT, discord_id TEXT)",
(err) => {
if (err) {
console.log("Failed to make table.");
return console.error(err.message);
}
console.log("Created Table");
},
)
.run(
"CREATE TABLE pledges(id INTEGER PRIMARY KEY AUTOINCREMENT, pledger_id INTEGER NOT NULL, veg_status INTEGER NOT NULL, start_date INTEGER NOT NULL, end_date INTEGER NOT NULL)",
(err) => {
if (err) {
console.log("Failed to make table.");
return console.error(err.message);
}
console.log("Created Table");
},
);
});
db.close((err) => {
if (err) {
return console.error(err.message);
}
console.log("Closed the database connection.");
});