-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdojoDAO.py
44 lines (36 loc) · 1.22 KB
/
dojoDAO.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
import dbConnection
def add_dojo():
conn = dbConnection.connect_to_database()
params = ("Warszawa", "Warszawskie", 5)
if conn.execute("INSERT (LOKALIZACJA, NAZWA, IL_MENTOROW) INTO dojo VALUES (?, ?, ?)", params):
dbConnection.commit(conn)
return True
else:
dbConnection.rollback(conn)
return False
def remove_dojo(dojoId):
conn = dbConnection.connect_to_database()
if conn.execute("DELETE FROM dojo WHERE ID = ?", dojoId):
dbConnection.commit(conn)
return True
else:
dbConnection.rollback(conn)
return False
def add_user_dojo_relation(userId, dojoId):
conn = dbConnection.connect_to_database()
params = (userId, dojoId)
if conn.execute("INSERT INTO dojo_user VALUES (?, ?)", params):
dbConnection.commit(conn)
return True
else:
dbConnection.rollback(conn)
return False
def remove_user_dojo_relation(userId, dojoId):
conn = dbConnection.connect_to_database()
params = (userId, dojoId)
if conn.execute("DELETE FROM dojo_user WHERE USER_ID = ? AND DOJO_ID = ?)", params):
dbConnection.commit(conn)
return True
else:
dbConnection.rollback(conn)
return False