From f39b693b3dbeeb89778c4bf9774a3e64ee2cea71 Mon Sep 17 00:00:00 2001 From: Sam Chau Date: Fri, 10 Jan 2025 00:44:22 +1030 Subject: [PATCH] feat: add function to retrieve unique import settings for multiple arr IDs --- backend/app/db.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/backend/app/db.py b/backend/app/db.py index 23a2aa2..42cc7f7 100644 --- a/backend/app/db.py +++ b/backend/app/db.py @@ -156,3 +156,34 @@ def save_settings(settings_dict): updated_at = CURRENT_TIMESTAMP ''', (key, value)) conn.commit() + + +def get_unique_arrs(arr_ids): + """ + Get import_as_unique settings for a list of arr IDs. + + Args: + arr_ids (list): List of arr configuration IDs + + Returns: + dict: Dictionary mapping arr IDs to their import_as_unique settings and names + """ + if not arr_ids: + return {} + + with get_db() as conn: + placeholders = ','.join('?' * len(arr_ids)) + query = f''' + SELECT id, name, import_as_unique + FROM arr_config + WHERE id IN ({placeholders}) + ''' + + results = conn.execute(query, arr_ids).fetchall() + return { + row['id']: { + 'import_as_unique': bool(row['import_as_unique']), + 'name': row['name'] + } + for row in results + }