-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_db.py
68 lines (67 loc) · 2.08 KB
/
test_db.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import logging
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import MetaData
from data_stuff import (
Buyer,
Seller,
Product,
Admin,
Cart,
Transaction
)
# logging.basicConfig()
# logging.getLogger('sqlalchemy').setLevel(logging.ERROR)
engine = create_engine('mysql+mysqlconnector://user:password@localhost:3306/DSTRY')
Base = declarative_base(bind=engine)
Session = sessionmaker(bind=engine)
session = Session()
try:
bhagat = Seller(name='aaryan bhagat', emailid='[email protected]', phone='123', password='3fg')
ankit = Seller(name='ankit bagde', emailid='[email protected]', password='asd', phone='123')
fan = Product(name='orient fan', price=34.5, quantity=2, seller=ankit)
sanket = Buyer(name='sanket', emailid='[email protected]', phone='34', address='sd', password='fg')
vasu = Buyer(name='gurrram', emailid='[email protected]', phone='45', address='sddd', password='asd')
bottle = Product(name='milton bottle', price=34.6, quantity=10, seller=ankit)
shoes = Product(name='Puma shoes', price=100.45, quantity=1, seller=bhagat)
session.add(bhagat)
session.add(ankit)
# print(type(ankit.products))
print(bhagat)
print(fan)
print(bottle)
print(shoes.seller)
cart_1 = Cart(product=bottle)
cart_2 = Cart(product=bottle)
cart_3 = Cart(product=bottle)
print(cart_1)
print(cart_2)
print(cart_3)
session.commit()
# print(ankit.emailid)
session.add(bottle)
session.add(shoes)
session.add(vasu)
session.add(sanket)
session.add(fan)
session.add(cart_1)
session.add(cart_2)
session.add(cart_3)
# print(cart_1.user)
print(cart_1.product)
# print(cart_2.user)
print(cart_2.product)
# print(cart_3.user)
print(cart_3.product)
session.commit()
print('Done')
finally:
print('Deleting all')
print(engine.table_names())
session.close()
meta = MetaData()
meta.reflect(bind=engine)
for table in reversed(meta.sorted_tables):
# print(table)
table.drop(engine)