-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbhelper.py
55 lines (45 loc) · 1.22 KB
/
dbhelper.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
54
55
import sqlite3
instance = None
def get_DBHelper_instance():
class DBHelper(object):
def __init__(self):
#open the connections
conn = sqlite3.connect('magic.db')
#create the tables if they dont exist
cursor = conn.cursor()
cursor.execute("""CREATE TABLE IF NOT EXISTS decks
(
name TEXT,
version INTEGER,
color TEXT,
creator TEXT
PRIMARY KEY (name, version));""")
cursor.execute(""" CREATE TABLE IF NOT EXISTS games
(
dateTime DATETIME PRIMARY KEY,
winningPlayer TEXT,
winningDeckName TEXT,
winningDeckVersion INTEGER,
winningMulligans INTEGER,
losingPlayer TEXT,
losingDeckName TEXT,
losingDeckVesrion INTEGER,
losingMulligans INTEGER
);""")
conn.commit()
conn.close()
def addDeck(self, name, version, color, creator):
#open the connections
with sqlite3.connect('magic.db') as conn:
cursor = conn.cursor()
cursor.execute("""INSERT INTO decks (
name, version, color, creator, wins, losses
)
VALUES (
?, ?, ?, ?, 0, 0
);""", (name, version, color, creator))
conn.commit()
global instance
if instance is None:
instance = DBHelper()
return instance