forked from learn-co-curriculum/python-p3-freebie-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.py
More file actions
40 lines (31 loc) · 1.11 KB
/
debug.py
File metadata and controls
40 lines (31 loc) · 1.11 KB
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
#!/usr/bin/env python3
# debug.py
from config import session, engine
from models import Dev, Company, Freebie
from sqlalchemy import create_engine, inspect
def show_tables():
inspector = inspect(engine)
tables = inspector.get_table_names()
print("Tables in the database:", tables)
def add_sample_data():
print("Adding sample data...")
dev = Dev(name="Chance")
company = Company(name="Chancy Founders", founding_year=2024)
freebie = Freebie(item_name="Milk", value=25, dev=dev, company=company)
session.add_all([dev, company, freebie])
session.commit()
print("Yay!Sample data added!")
def query_data():
print("--------/n Querying data...--------------------/n")
devs = session.query(Dev).all()
companies = session.query(Company).all()
freebies = session.query(Freebie).all()
print(f"Devs: {[d.name for d in devs]}")
print(f"Companies: {[c.name for c in companies]}")
print(f"Freebies: [{', '.join(f'{f.item_name} (value: {f.value})' for f in freebies)}]")
def main():
show_tables()
add_sample_data()
query_data()
if __name__ == "__main__":
main()