about summary refs log tree commit diff
path: root/uploader/publications/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'uploader/publications/models.py')
-rw-r--r--uploader/publications/models.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/uploader/publications/models.py b/uploader/publications/models.py
index dcfa02b..d913144 100644
--- a/uploader/publications/models.py
+++ b/uploader/publications/models.py
@@ -101,6 +101,20 @@ def fetch_publication_by_id(conn: Connection, publication_id: int) -> dict:
         return dict(_res) if _res else {}
 
 
+def fetch_publications_by_ids(
+        conn: Connection, publications_ids: tuple[int, ...]
+) -> tuple[dict, ...]:
+    """Fetch publications with the given IDs."""
+    if len(publications_ids) == 0:
+        return tuple()
+
+    with conn.cursor(cursorclass=DictCursor) as cursor:
+        paramstr = ", ".join(["%s"] * len(publications_ids))
+        cursor.execute(f"SELECT * FROM Publication WHERE Id IN ({paramstr})",
+                       tuple(publications_ids))
+        return tuple(dict(row) for row in cursor.fetchall())
+
+
 def fetch_publication_phenotypes(
         conn: Connection, publication_id: int) -> Iterable[dict]:
     """Fetch all phenotypes linked to this publication."""