046
This commit is contained in:
parent
a277f23cc3
commit
a144847869
4 changed files with 46 additions and 2 deletions
BIN
src/db/db_up
BIN
src/db/db_up
Binary file not shown.
|
@ -1,8 +1,10 @@
|
||||||
import
|
import
|
||||||
./[users, products],
|
./[users, products, orders, orderitems],
|
||||||
../lib/mics
|
../lib/mics
|
||||||
|
|
||||||
var conn = newTurso()
|
var conn = newTurso()
|
||||||
|
|
||||||
setupUsers(conn)
|
setupUsers(conn)
|
||||||
setupProducts(conn)
|
setupProducts(conn)
|
||||||
|
setupOrders(conn)
|
||||||
|
setupOrderItems(conn)
|
||||||
|
|
19
src/db/orderitems.nim
Normal file
19
src/db/orderitems.nim
Normal 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
23
src/db/orders.nim
Normal 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)
|
||||||
|
);
|
||||||
|
""")
|
Loading…
Reference in a new issue