-
Notifications
You must be signed in to change notification settings - Fork 0
/
database.js
166 lines (163 loc) · 4.97 KB
/
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
var sqlite3 = require('sqlite3').verbose()
const DBSOURCE = "db.sqlite"
let db = new sqlite3.Database(DBSOURCE, (err) => {
if (err) {
// Cannot open database
console.error(err.message)
throw err
}else{
console.log('Connected to the SQLite database.')
db.run(`CREATE TABLE user (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name text,
email text UNIQUE,
password text,
role text,
security_question text,
approval text,
CONSTRAINT email_unique UNIQUE (email)
)`,
(err) => {
if (err) {
// Table already created
console.log('user table already exists')
}else{
// Table just created
console.log('user table created')
}
});
db.run(`CREATE TABLE members (
id INTEGER PRIMARY KEY AUTOINCREMENT,
title text,
first_name text,
surname text,
sex text,
email text,
phone_number text,
house_number INTEGER,
address_line_1 text,
address_line_2 text,
city text,
postcode text,
date_of_birth date,
baptised text,
baptised_date date,
holy_spirit text,
native_church text,
children_details text,
emergency_contact_1 INTEGER,
emergency_contact_1_name text,
emergency_contact_2 INTEGER,
emergency_contact_2_name text,
occupation_studies text,
spouse_name text,
banking_name text
)`,
(err) => {
if (err) {
// Table already created
console.log('members table already exists')
}else{
// Table just created
console.log('members table created')
}
});
db.run(`CREATE TABLE donations (
id INTEGER PRIMARY KEY AUTOINCREMENT,
member_id INTEGER,
first_name text,
surname text,
amount text,
date date,
fund text,
method text,
gift_aid_status text,
notes text
)`,
(err) => {
if (err) {
// Table already created
console.log('donations table already exists')
}else{
// Table just created
console.log('donations table created')
}
});
db.run(`CREATE TABLE transactions (
id INTEGER PRIMARY KEY AUTOINCREMENT,
date date,
transaction_type text,
type text,
description text,
paid_out text,
paid_in text,
balance text,
notes text
)`,
(err) => {
if (err) {
// Table already created
console.log('transactions table already exists')
}else{
// Table just created
console.log('transactions table created')
}
})
db.run(`CREATE TABLE last_update (
id INTEGER PRIMARY KEY AUTOINCREMENT,
timestamp text,
user text
)`,
(err) => {
if (err) {
// Table already created
console.log('last_update table already exists')
}else{
// Table just created
console.log('last_update table created')
}
})
db.run(`CREATE TABLE console_logs (
id INTEGER PRIMARY KEY AUTOINCREMENT,
timestamp text,
user text,
log_message text
)`,
(err) => {
if (err) {
// Table already created
console.log('logs table already exists')
}else{
// Table just created
console.log('logs table created')
}
});
db.run(`CREATE TABLE transaction_types (
id INTEGER PRIMARY KEY AUTOINCREMENT,
type text UNIQUE NOT NULL
)`,
(err) => {
if (err) {
// Table already created
console.log('transaction_types table already exists')
}else{
// Table just created
console.log('transaction_types table created')
}
});
db.run(`CREATE TABLE donation_types (
id INTEGER PRIMARY KEY AUTOINCREMENT,
type text UNIQUE NOT NULL
)`,
(err) => {
if (err) {
// Table already created
console.log('donation_types table already exists')
}else{
// Table just created
console.log('donation_types table created')
}
});
}
});
module.exports = db