-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatamanager.py
More file actions
31 lines (23 loc) · 792 Bytes
/
datamanager.py
File metadata and controls
31 lines (23 loc) · 792 Bytes
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
from psycopg2.extras import RealDictCursor
import database
@database.connection_handler
def db_mod_list_with_return(cursor: RealDictCursor, query, list_of_var) -> list:
cursor.execute(query, list_of_var)
return cursor.fetchall()
@database.connection_handler
def db_mod_list_without_return(cursor: RealDictCursor, query, list_of_var):
cursor.execute(query, list_of_var)
def get_scores():
query = '''
SELECT *
FROM scores
ORDER BY score DESC
LIMIT 10'''
list_of_var = []
return db_mod_list_with_return(query=query, list_of_var=list_of_var)
def write_score(username, score):
query = '''
INSERT INTO scores
VALUES (%s, %s)'''
list_of_var = [username, int(score)]
db_mod_list_without_return(query=query, list_of_var=list_of_var)