rework elsa media database function
This commit is contained in:
@@ -147,7 +147,11 @@ class Database:
|
|||||||
"""
|
"""
|
||||||
conn = self.connect()
|
conn = self.connect()
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
self.logger.log_info(f"Querying database with query {query}, args: {args}")
|
log_message = f"Querying database with query {query}, args: {args}"
|
||||||
|
if "INSERT" in query:
|
||||||
|
log_message = f"Querying database with query {query}"
|
||||||
|
|
||||||
|
self.logger.log_info(log_message)
|
||||||
|
|
||||||
cursor.execute(query, args)
|
cursor.execute(query, args)
|
||||||
rv = cursor.fetchall()
|
rv = cursor.fetchall()
|
||||||
@@ -1324,21 +1328,17 @@ class Database:
|
|||||||
|
|
||||||
Args:
|
Args:
|
||||||
data (dict): a dictionary containing the data of the media,
|
data (dict): a dictionary containing the data of the media,
|
||||||
Structured: {"chapter":str, "title":str, "signature":str, "pages":str}
|
elsa_id (int): the id of the ELSA apparat
|
||||||
"""
|
"""
|
||||||
self.query_db(
|
headers = []
|
||||||
"INSERT INTO elsa_media (chapter, title, signature, pages,book_author,text_author, elsa_id) VALUES (?,?,?,?,?,?,?)",
|
entries = []
|
||||||
(
|
for key, value in data.items():
|
||||||
data["chapter"],
|
headers.append(key)
|
||||||
data["title"],
|
entries.append(value)
|
||||||
data["signature"],
|
headers.append("elsa_id")
|
||||||
data["pages"],
|
entries.append(elsa_id)
|
||||||
data["book_author"],
|
query = f"INSERT INTO elsa_media ({', '.join(headers)}) VALUES ({', '.join(['?' for i in range(len(headers))])})"
|
||||||
data["text_author"],
|
self.query_db(query, entries)
|
||||||
elsa_id,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
def getElsaMedia(self, elsa_id: int):
|
def getElsaMedia(self, elsa_id: int):
|
||||||
"""get all the media of an ELSA apparat
|
"""get all the media of an ELSA apparat
|
||||||
|
|
||||||
@@ -1348,7 +1348,16 @@ class Database:
|
|||||||
Returns:
|
Returns:
|
||||||
list[tuple]: a list of tuples containing the media
|
list[tuple]: a list of tuples containing the media
|
||||||
"""
|
"""
|
||||||
return self.query_db("SELECT * FROM elsa_media WHERE elsa_id=?", (elsa_id,))
|
media = self.query_db("SELECT * FROM elsa_media WHERE elsa_id=?", (elsa_id,))
|
||||||
|
# convert the media to a list of dictionaries
|
||||||
|
ret = []
|
||||||
|
table_fields = self.query_db("PRAGMA table_info(elsa_media)")
|
||||||
|
for m in media:
|
||||||
|
tmp = {}
|
||||||
|
for i in range(len(m)):
|
||||||
|
tmp[table_fields[i][1]] = m[i]
|
||||||
|
ret.append(tmp)
|
||||||
|
return ret
|
||||||
|
|
||||||
def insertElsaFile(self, file: list[dict], elsa_id: int):
|
def insertElsaFile(self, file: list[dict], elsa_id: int):
|
||||||
"""Instert a list of files into the ELSA system
|
"""Instert a list of files into the ELSA system
|
||||||
|
|||||||
Reference in New Issue
Block a user