Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"githubPullRequests.ignoredPullRequestBranches": [
"main"
]
}
104 changes: 62 additions & 42 deletions database.js
Original file line number Diff line number Diff line change
@@ -1,60 +1,80 @@
var sqlite3 = require('sqlite3').verbose()
var md5 = require('md5')

const DBSOURCE = "db.sqlite"
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
console.error(err.message);
throw err;
} else {
console.log('Connected to the SQlite database.')
console.log('Connected to the SQLite database.');

// Create products table
db.run(`CREATE TABLE products (
id INTEGER PRIMARY KEY AUTOINCREMENT,
productName text,
description text,
category text,
brand text,
expiredDate text,
manufacturedDate text,
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"])
createdDate TEXT
)`, (err) => {
if (!err) {
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"
]);
}
})

});

// Create suppliers table
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"])

supplierName TEXT,
address TEXT,
joinedDate TEXT,
mobileNo TEXT
)`, (err) => {
if (!err) {
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"]);
}
})


});

// Create customer table
db.run(`CREATE TABLE customer (
customerId INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
address TEXT NOT NULL,
email TEXT NOT NULL UNIQUE,
dateOfBirth TEXT NOT NULL,
gender TEXT NOT NULL,
age INTEGER NOT NULL,
cardHolderName TEXT NOT NULL,
cardNumber TEXT NOT NULL CHECK(LENGTH(cardNumber) = 12),
expiryDate TEXT NOT NULL,
cvv TEXT NOT NULL CHECK(LENGTH(cvv) = 3),
timeStamp TEXT NOT NULL
)`, (err) => {
if (!err) {
console.log("Customer table created.");
}
});
}
})

module.exports = db
});

module.exports = db;
Loading