Refactor to use .query

All the other methods of this class call through to query, we can make
this code clearer by making `get_areas` do the same.
This commit is contained in:
Chris Hill-Scott
2020-08-12 09:45:22 +01:00
parent adad27dadb
commit e267e3d9f1

View File

@@ -123,24 +123,21 @@ class BroadcastAreasRepository(object):
description = self.query(q, library_id)[0][0]
return description
def get_areas(self, *area_ids):
with self.conn() as conn:
cursor = conn.cursor()
def get_areas(self, area_ids):
q = """
SELECT id, name
FROM broadcast_areas
WHERE id IN ({})
""".format(("?," * len(area_ids))[:-1])
q = """
SELECT id, name
FROM broadcast_areas
WHERE id IN ({})
""".format(("?," * len(*area_ids))[:-1])
cursor.execute(q, *area_ids)
results = cursor.fetchall()
results = self.query(q, *area_ids)
areas = [
(row[0], row[1])
for row in results
]
areas = [
(row[0], row[1])
for row in results
]
return areas
return areas
def get_all_areas_for_library(self, library_id):
q = """