-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathdatabase.js
More file actions
60 lines (49 loc) · 1.96 KB
/
Copy pathdatabase.js
File metadata and controls
60 lines (49 loc) · 1.96 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
var sqlite3 = require('sqlite3').verbose()
var md5 = require('md5')
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 products (
id INTEGER PRIMARY KEY AUTOINCREMENT,
productName text,
description text,
category text,
brand text,
expiredDate text,
manufacturedDate text,
batchNumber INTEGER,
unitPrice INTEGER,
quantity INTEGER,
createdDate text
)`, (err) => {
if (err) {
// Table already created
} else {
// Table just created, creating some rows
var insert = 'INSERT INTO products (productName, description, category, brand, expiredDate, manufacturedDate, batchNumber, unitPrice, quantity, createdDate) VALUES (?,?,?,?,?,?,?,?,?,?)'
db.run(insert, ["White Basmathi Rice", "White Basmathi Rice imported from Pakistan. High-quality rice with extra fragrance. Organically grown.", "Rice", "CIC", "2023.05.04", "2022.02.20", 324567, , 1020, 200, "2022.02.24"])
}
})
db.run(`CREATE TABLE suppliers (
id INTEGER PRIMARY KEY AUTOINCREMENT,
supplierName text,
address text,
joinedDate text,
mobileNo text
)`, (err) => {
if (err) {
// Table already created
} else {
// Table just created, creating some rows
var insert = 'INSERT INTO suppliers (supplierName, address, joinedDate, mobileNo) VALUES (?,?,?,?)'
db.run(insert, ["D.J.Ishara", "345A ,R.A De Mel Road, Colombo 3", "16/3/2022", "0776600933"])
}
})
}
})
module.exports = db