Merge pull request '046' (#29) from ayushman into main

Reviewed-on: #29
This commit is contained in:
cereci5049 2024-08-17 21:22:34 +02:00
commit 3c7a992f81
4 changed files with 46 additions and 2 deletions

Binary file not shown.

View file

@ -1,8 +1,10 @@
import
./[users, products],
./[users, products, orders, orderitems],
../lib/mics
var conn = newTurso()
setupUsers(conn)
setupProducts(conn)
setupProducts(conn)
setupOrders(conn)
setupOrderItems(conn)

19
src/db/orderitems.nim Normal file
View file

@ -0,0 +1,19 @@
import
turso,
strformat,
json,
strutils,
../model/model
proc setupOrderItems*(conn: Turso) =
conn.execute("""
CREATE TABLE OrderItems (
id INTEGER PRIMARY KEY AUTOINCREMENT,
orderId INTEGER,
productId INTEGER,
quantity INTEGER,
price REAL,
FOREIGN KEY (orderId) REFERENCES Orders(id),
FOREIGN KEY (productId) REFERENCES Products(id)
);
""")

23
src/db/orders.nim Normal file
View file

@ -0,0 +1,23 @@
import
turso,
strformat,
json,
strutils,
../model/model
proc setupOrders*(conn: Turso) =
conn.execute("""
CREATE TABLE IF NOT EXISTS Orders (
id INTEGER PRIMARY KEY AUTOINCREMENT,
buyerId INTEGER,
orderDate DATE,
orderStatus TEXT,
shippingAddressId INTEGER,
billingAddressId INTEGER,
createdAt TEXT DEFAULT CURRENT_TIMESTAMP NOT NULL,
updatedAt TEXT DEFAULT CURRENT_TIMESTAMP NOT NULL,
FOREIGN KEY (buyerId) REFERENCES Users(id),
FOREIGN KEY (shippingAddressId) REFERENCES Addresses(id),
FOREIGN KEY (billingAddressId) REFERENCES Addresses(id)
);
""")