-
Notifications
You must be signed in to change notification settings - Fork 0
/
select_data.py
53 lines (36 loc) · 1.36 KB
/
select_data.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
from database import SessionLocal
import logging
from models import Hospital, Patient, Doctor
def select_all_hospitals():
try:
with SessionLocal() as session:
hospitals = session.query(Hospital).all()
# Display hospital object individually
for hospital in hospitals:
logging.info(hospital)
# Display total number of the hospitals in database
logging.info(f"Total hospital number: {len(hospitals)}")
except Exception as e:
logging.error(f"Error selecting hospitals: {e}")
def select_all_patients():
try:
with SessionLocal() as session:
patients = session.query(Patient).all()
for patient in patients:
logging.info(patient)
logging.info(f"Total patient number: {len(patients)}")
except Exception as e:
logging.error(f"Error selecting patients: {e}")
def select_all_doctors():
try:
with SessionLocal() as session:
doctors = session.query(Doctor).all()
for doctor in doctors:
logging.info(doctor)
logging.info(f"Total doctor number: {len(doctors)}")
except Exception as e:
logging.error(f"Error selecting doctors: {e}")
if __name__ == "__main__":
# select_all_hospitals()
# select_all_patients()
select_all_doctors()