-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb_manager.py
More file actions
31 lines (23 loc) · 745 Bytes
/
db_manager.py
File metadata and controls
31 lines (23 loc) · 745 Bytes
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
import os
import sys
from PyQt5 import QtSql
def retrieve_path(relative_path):
try:
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)
class DbManager:
def __init__(self, app_name):
dir_path = retrieve_path('data')
if not os.path.exists(dir_path):
os.makedirs(dir_path)
file_path = os.path.join(dir_path, app_name + '.db')
self.db = QtSql.QSqlDatabase.addDatabase("QSQLITE")
self.db.setDatabaseName(file_path)
if not self.db.open():
sys.exit(-1)
def exec(self, statement):
query = QtSql.QSqlQuery()
query.exec(statement)
return query