Add get_file_data() function to datastore

This commit is contained in:
D. Berge
2023-09-12 11:04:37 +02:00
parent 0a9bde5f10
commit b71489cee1

View File

@@ -589,7 +589,33 @@ class Datastore:
# We do not commit if we've been passed a cursor, instead # We do not commit if we've been passed a cursor, instead
# we assume that we are in the middle of a transaction # we assume that we are in the middle of a transaction
def get_file_data(self, path, cursor = None):
"""
Retrieve arbitrary data associated with a file.
"""
if cursor is None:
cur = self.conn.cursor()
else:
cur = cursor
realpath = configuration.translate_path(path)
hash = file_hash(realpath)
qry = """
SELECT data
FROM file_data
WHERE hash = %s;
"""
cur.execute(qry, (hash,))
res = cur.fetchone()
if cursor is None:
self.maybe_commit()
# We do not commit if we've been passed a cursor, instead
# we assume that we are in the middle of a transaction
return res[0]
def surveys (self, include_archived = False): def surveys (self, include_archived = False):
""" """