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:
parent
8c1a8bde54
commit
ce0a2d9213
@ -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(
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user