-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdatabase.js
More file actions
37 lines (34 loc) · 998 Bytes
/
database.js
File metadata and controls
37 lines (34 loc) · 998 Bytes
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
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 products (
id INTEGER PRIMARY KEY AUTOINCREMENT,
productName text,
description text,
unitPrice INTEGER
)`,
(err) => {
if (err) {
// Table already created
} else {
// Table just created, creating some rows
var insert =
"INSERT INTO products (productName, description, unitPrice) VALUES (?,?,?)";
db.run(insert, [
"White Basmathi Rice",
"White Basmathi Rice imported from Pakistan. High-quality rice with extra fragrance. Organically grown.",
200,
]);
}
}
);
}
});
module.exports = db;