-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsql_helper.py
53 lines (42 loc) · 1.05 KB
/
sql_helper.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
import sqlite3
def start():
global con
global cur
con = sqlite3.connect("persistent_data/database.db")
cur = con.cursor()
def stop():
global con
global cur
cur.close()
con.close()
# TODO throw exception when keys don't match
def select_game(game: dict):
cur.execute(
"""SELECT * FROM free_games WHERE
id = ? AND
title = ? AND
free_after = ? AND
free_until = ?;""",
(
game["id"],
game["title"],
game["free_after"],
game["free_until"],
),
)
return cur.fetchall()
def contains_game(game: dict):
return len(select_game(game)) > 0
def insert_game(game: dict):
cur.execute(
"""INSERT INTO free_games (id, title, description, image, free_after, free_until) VALUES(?,?,?,?,?,?);""",
(
game["id"],
game["title"],
game["description"],
game["image"],
game["free_after"],
game["free_until"],
),
)
con.commit()