This repository has been archived by the owner on Feb 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDatabase.py
61 lines (51 loc) · 2.17 KB
/
Database.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
56
57
58
59
60
61
import sqlite3
from Warrior import Warrior
from Hero import Hero
from Army import Army
from Option import Option
from ForeignOption import ForeignOption
class Database:
def __init__(self, db):
self.db = db
def connect(self):
return sqlite3.connect(self.db)
def get_warrior(self, w):
conn = self.connect()
cursor = conn.cursor()
cursor.execute('SELECT * FROM Warriors WHERE Name LIKE ?', (w,))
return Warrior.from_database(cursor.fetchone())
def get_hero(self, h):
conn = self.connect()
cursor = conn.cursor()
cursor.execute('SELECT * FROM Heroes WHERE Name LIKE ?', (h,))
return Hero.from_database(cursor.fetchone())
def get_all_Warriors(self):
conn = self.connect()
cursor = conn.cursor()
cursor.execute('SELECT * FROM Warriors')
return [Warrior.from_database(data) for data in cursor.fetchall()]
def get_all_warriors_from_army(self, army):
conn = self.connect()
cursor = conn.cursor()
cursor.execute('SELECT * FROM Warriors WHERE isInArmy LIKE ?', (army,))
return [Warrior.from_database(data) for data in cursor.fetchall()]
def get_all_heroes_from_army(self, army):
conn = self.connect()
cursor = conn.cursor()
cursor.execute('SELECT * FROM Heroes WHERE isInArmy LIKE ?', (army,))
return [Hero.from_database(data) for data in cursor.fetchall()]
def get_all_armies(self):
conn = self.connect()
cursor = conn.cursor()
cursor.execute('SELECT * FROM Armies')
return [Army.from_database(data) for data in cursor.fetchall()]
def get_all_options_for_unit(self, name):
conn = self.connect()
cursor = conn.cursor()
cursor.execute('SELECT * FROM Options WHERE Unit LIKE ?', (name,))
return [Option.from_database(data) for data in cursor.fetchall()]
def get_all_foreign_options_for_unit(self, name):
conn = self.connect()
cursor = conn.cursor()
cursor.execute('SELECT * FROM ForeignOptions WHERE ReceivingUnit LIKE ?', (name,))
return [ForeignOption.from_database(data) for data in cursor.fetchall()]