Skip to content

Commit

Permalink
added initialization function for 'transactions' table
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdcvlsc committed May 12, 2022
1 parent 7e61c77 commit c5cea7c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
18 changes: 18 additions & 0 deletions controllers/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,24 @@ const InventoryDB = {
return true;
},

init_transactions : function(db, transactionTableName) {
try{
db.exec(`
CREATE TABLE ${transactionTableName} (
buydata DATE NOT NULL,
itemname TEXT NOT NULL,
price REAL NOT NULL,
quantity INTEGER NOT NULL
)`
);
}
catch(err) {
ErrorHandler(err,'init_transactions');
return false;
}
return true;
},

insertRow : function(insertStatement, Product, Class, Price, Quantity) {
let result;
try {
Expand Down
1 change: 1 addition & 0 deletions controllers/items.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const { InventoryDB, ErrorHandler } = require('./database');

try {
InventoryDB.initialize(db,'inventory');
InventoryDB.init_transactions(db,'transactions');
var insertStatement = db.prepare(InventoryDB.StmTemp.INSERT);
var updateStatement = db.prepare(InventoryDB.StmTemp.UPDATE);
var deleteStatement = db.prepare(InventoryDB.StmTemp.DELETE);
Expand Down
Binary file modified data/database.db
Binary file not shown.
12 changes: 6 additions & 6 deletions db-schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
-----

## transactions
| Row Name | Data Type | Properties |
| :------: | :-------: | :------------------: |
| buydate | DATE | NOT NULL |
| itemname | TEXT | NOT NULL |
| price | REAL | NOT NULL |
| quantity | INTEGER | NOT NULL |
| Row Name | Data Type | Properties |
| :------: | :-------: | :------------: |
| buydate | DATE | NOT NULL |
| itemname | TEXT | NOT NULL |
| price | REAL | NOT NULL |
| quantity | INTEGER | NOT NULL |

0 comments on commit c5cea7c

Please sign in to comment.