1
0
mirror of https://github.com/ilri/dspace-statistics-api.git synced 2025-04-14 02:29:23 +02:00

Adjust psycopg connection for dict_row factory

This commit is contained in:
Alan Orth 2025-04-01 17:42:41 +03:00
parent 8c1a8bde54
commit ce0a2d9213
Signed by: alanorth
GPG Key ID: 0FB860CC9C45B1B9
2 changed files with 5 additions and 6 deletions

View File

@ -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(

View File

@ -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)