-
Notifications
You must be signed in to change notification settings - Fork 1
/
database.py
42 lines (30 loc) · 881 Bytes
/
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
"""
This class is a set of helper methods for the SQLite database.
"""
import sqlite3
DATABASE_PATH = "database.db"
class _Database:
@staticmethod
def get_connection():
return sqlite3.connect(DATABASE_PATH)
@staticmethod
def get_one_fetched_as_dict(cursor):
desc = cursor.description
row = cursor.fetchone()
new_dict = {}
if row is not None:
for i in range(len(row)):
new_dict[desc[i][0]] = row[i]
return new_dict
@staticmethod
def get_all_fetched_as_dict(cursor):
desc = cursor.description
lst = cursor.fetchall()
fetched = []
for row in lst:
new_dict = {}
for i in range(len(row)):
new_dict[desc[i][0]] = row[i]
fetched.append(new_dict)
return fetched
database = _Database()