update database functionality
This commit is contained in:
@@ -39,11 +39,9 @@ class Database:
|
||||
return None
|
||||
|
||||
def connect(self):
|
||||
logger.log_info("Connecting to database")
|
||||
return sql.connect(self.db_path)
|
||||
|
||||
def close_connection(self, conn: sql.Connection):
|
||||
logger.log_info("Closing database connection")
|
||||
conn.close()
|
||||
|
||||
def create_tables(self):
|
||||
@@ -115,7 +113,13 @@ class Database:
|
||||
def getBookIdBasedOnSignature(self, app_id:str, prof_id:str,signature:str)->int:
|
||||
result = self.query_db("SELECT bookdata, id FROM media WHERE app_id=? AND prof_id=?", (app_id,prof_id))
|
||||
books = [(load_pickle(i[0]),i[1]) for i in result]
|
||||
book = [i for i in books if i[0].signature == signature][1]
|
||||
# ic(books)
|
||||
book = [i for i in books if i[0].signature == signature][0]
|
||||
return book
|
||||
def getBookBasedOnSignature(self, app_id:str, prof_id:str,signature:str)->BookData:
|
||||
result = self.query_db("SELECT bookdata FROM media WHERE app_id=? AND prof_id=?", (app_id,prof_id))
|
||||
books = [load_pickle(i[0]) for i in result]
|
||||
book = [i for i in books if i.signature == signature][0]
|
||||
return book
|
||||
def getLastBookId(self)->int:
|
||||
return self.query_db("SELECT id FROM media ORDER BY id DESC", one=True)[0]
|
||||
@@ -210,6 +214,7 @@ class Database:
|
||||
delete=False, dir=tempdir_path, mode="wb", suffix=f".{filetype}"
|
||||
)
|
||||
file.write(blob)
|
||||
print("file created")
|
||||
return file.name
|
||||
def getFiles(self, app_id:int, prof_id:int)->list[tuple]:
|
||||
return self.query_db("SELECT filename, filetyp FROM files WHERE app_id=? AND prof_id=?", (app_id,prof_id))
|
||||
@@ -315,7 +320,9 @@ class Database:
|
||||
- number(List[int]): a list of all currently used apparat numbers
|
||||
"""
|
||||
numbers = self.query_db("SELECT appnr FROM semesterapparat WHERE deletion_status=0")
|
||||
return [i[0] for i in numbers]
|
||||
numbers = [i[0] for i in numbers]
|
||||
logger.log_info(f"Currently used apparat numbers: {numbers}")
|
||||
return numbers
|
||||
def setNewSemesterDate(self, appnr, newDate, dauerapp=False):
|
||||
date = datetime.datetime.strptime(newDate, "%d.%m.%Y").strftime("%Y-%m-%d")
|
||||
if dauerapp:
|
||||
@@ -415,7 +422,8 @@ class Database:
|
||||
self.query_db(query, params)
|
||||
def checkApparatExists(self, apparat_name):
|
||||
return True if self.query_db("SELECT appnr FROM semesterapparat WHERE name=?", (apparat_name,), one=True) else False
|
||||
|
||||
def checkApparatExistsById(self, apparat_id):
|
||||
return True if self.query_db("SELECT appnr FROM semesterapparat WHERE appnr=?", (apparat_id,), one=True) else False
|
||||
# Statistics
|
||||
def statistic_request(self, **kwargs: Any):
|
||||
def __query(query):
|
||||
|
||||
Reference in New Issue
Block a user