-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase_interface.py
More file actions
58 lines (50 loc) · 1.73 KB
/
database_interface.py
File metadata and controls
58 lines (50 loc) · 1.73 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
import sqlite3
import os
DATABASE_PATH = 'limitless_decks.db'
class Connection:
def __init__(self):
# Connect to SQLite database
self.conn = sqlite3.connect(DATABASE_PATH)
self.cursor = self.conn.cursor()
def _create_tables(self):
# Create tables
self.cursor.execute('''
CREATE TABLE IF NOT EXISTS players (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL UNIQUE
)
''')
self.cursor.execute('''
CREATE TABLE IF NOT EXISTS archetypes (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL UNIQUE
)
''')
self.cursor.execute('''
CREATE TABLE IF NOT EXISTS cards (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
set_name TEXT NOT NULL,
collection_number INTEGER NOT NULL,
UNIQUE (name, set_name, collection_number)
)
''')
self.cursor.execute('''
CREATE TABLE IF NOT EXISTS decks (
id INTEGER PRIMARY KEY,
player_id INTEGER NOT NULL,
archetype_id INTEGER NOT NULL,
FOREIGN KEY (player_id) REFERENCES players(id),
FOREIGN KEY (archetype_id) REFERENCES archetypes(id)
)
''')
self.cursor.execute('''
CREATE TABLE IF NOT EXISTS deck_cards (
id INTEGER PRIMARY KEY,
deck_id INTEGER NOT NULL,
card_id INTEGER NOT NULL,
count INTEGER NOT NULL,
FOREIGN KEY (deck_id) REFERENCES decks(id),
FOREIGN KEY (card_id) REFERENCES cards(id)
)
''')