-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathallQu.py
More file actions
64 lines (46 loc) · 1.84 KB
/
allQu.py
File metadata and controls
64 lines (46 loc) · 1.84 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from sqlalchemy.orm import sessionmaker
from connection import engine, User
import logging
# [ Ignore byDefault ] DEBUG: Detailed information, typically of interest only when diagnosing problems.
# [ Ignore byDefault ] INFO: Confirmation that things are working as expected.
# WARNING: An indication that something unexpected happened, or indicative of some problem in the near future (e.g. ‘disk space low’). The software is still working as expected.
# ERROR: Due to a more serious problem, the software has not been able to perform some function.
# CRITICAL: A serious error, indicating that the program itself may be unable to continue running.
logging.basicConfig(level=logging.DEBUG, filename='test.log',
format='%(asctime)s:%(levelname)s:%(message)s')
Session = sessionmaker(bind=engine)
def display_data():
session = Session()
users = session.query(User).all()
for user in users:
print("user : {} || id : {}".format(user.username, user.id))
session.close()
def insert_data():
session = Session()
uname = input("Enter Username : ")
user = User()
user.username = uname
session.add(user)
session.commit()
session.close()
def update_data():
session = Session()
uid = input("Enter the id : ")
u_id = '{}'.format(uid)
u_name = input("Enter username : ")
x = session.query(User).filter(User.id == u_id).first()
x.username = u_name
logging.debug(x)
session.commit()
session.close()
def delete_data():
session = Session()
uid = input("Enter Id to delete : ")
u_id = '{}'.format(uid)
x = session.query(User).filter(User.id == u_id). \
delete(synchronize_session=False)
session.commit()
session.close()
display_data()
# update_data()
# logging.debug(update_data())