diff --git a/dspace_statistics_api/app.py b/dspace_statistics_api/app.py index 1e266b2..fa07165 100644 --- a/dspace_statistics_api/app.py +++ b/dspace_statistics_api/app.py @@ -81,7 +81,7 @@ class AllStatisticsResource: with db.cursor() as cursor: # get total number of communities/collections/items so we can estimate the pages cursor.execute(f"SELECT COUNT(id) FROM {req.context.statistics_scope}") - pages = math.ceil(cursor.fetchone()[0] / limit) + pages = math.ceil(cursor.fetchone()['count'] / limit) # get statistics and use limit and offset to page through results cursor.execute( diff --git a/dspace_statistics_api/database.py b/dspace_statistics_api/database.py index 94f7a7c..ad9990a 100644 --- a/dspace_statistics_api/database.py +++ b/dspace_statistics_api/database.py @@ -1,8 +1,7 @@ # SPDX-License-Identifier: GPL-3.0-only import falcon -import psycopg2 -import psycopg2.extras +import psycopg from .config import ( DATABASE_HOST, @@ -21,10 +20,10 @@ class DatabaseManager: def __enter__(self): try: - self._connection = psycopg2.connect( - self._connection_uri, cursor_factory=psycopg2.extras.DictCursor + self._connection = psycopg.connect( + self._connection_uri, row_factory=psycopg.rows.dict_row ) - except psycopg2.OperationalError: + except psycopg.OperationalError: title = "500 Internal Server Error" description = "Could not connect to database" raise falcon.HTTPInternalServerError(title, description)