Merge pull request 'main' (#4) from cereci5049/8:main into main

Reviewed-on: harshscool955952/8#4
This commit is contained in:
harshscool955952 2024-08-18 08:56:33 +02:00
commit 2fe5b6a320
7 changed files with 106 additions and 2 deletions

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

@ -0,0 +1,19 @@
import
turso,
strformat,
json,
strutils,
../model/model
proc setupAddresses*(conn: Turso) =
conn.execute("""
CREATE TABLE Addresses (
id INTEGER PRIMARY KEY AUTOINCREMENT,
userId INTEGER,
address TEXT NOT NULL,
city TEXT NOT NULL,
state TEXT NOT NULL,
postalCode TEXT,
FOREIGN KEY (userId) REFERENCES Users(id)
);
""")

Binary file not shown.

View file

@ -1,8 +1,13 @@
import
./[users, products],
./[users, products, orders, orderitems, addresses, payments, reviews],
../lib/mics
var conn = newTurso()
setupUsers(conn)
setupProducts(conn)
setupProducts(conn)
setupOrders(conn)
setupOrderItems(conn)
setupAddresses(conn)
setupPayments(conn)
setupReviews(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)
);
""")

18
src/db/payments.nim Normal file
View file

@ -0,0 +1,18 @@
import
turso,
strformat,
json,
strutils,
../model/model
proc setupPayments*(conn: Turso) =
conn.execute("""
CREATE TABLE Payments (
id INTEGER PRIMARY KEY AUTOINCREMENT,
orderId INTEGER,
paymentAmount REAL,
paymentMethod TEXT,
paymentDate DATE,
FOREIGN KEY (orderId) REFERENCES Orders(id)
);
""")

20
src/db/reviews.nim Normal file
View file

@ -0,0 +1,20 @@
import
turso,
strformat,
json,
strutils,
../model/model
proc setupReviews*(conn: Turso) =
conn.execute("""
CREATE TABLE Reviews (
id INTEGER PRIMARY KEY AUTOINCREMENT,
productId INTEGER,
buyerId INTEGER,
rating INTEGER,
comment TEXT,
reviewDate DATE,
FOREIGN KEY (productId) REFERENCES Products(id),
FOREIGN KEY (buyerId) REFERENCES Users(id)
);
""")