mirror of
https://github.com/ilri/dspace-statistics-api.git
synced 2025-04-19 13:07:40 +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:
|
with db.cursor() as cursor:
|
||||||
# get total number of communities/collections/items so we can estimate the pages
|
# get total number of communities/collections/items so we can estimate the pages
|
||||||
cursor.execute(f"SELECT COUNT(id) FROM {req.context.statistics_scope}")
|
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
|
# get statistics and use limit and offset to page through results
|
||||||
cursor.execute(
|
cursor.execute(
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
# SPDX-License-Identifier: GPL-3.0-only
|
# SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
|
||||||
import falcon
|
import falcon
|
||||||
import psycopg2
|
import psycopg
|
||||||
import psycopg2.extras
|
|
||||||
|
|
||||||
from .config import (
|
from .config import (
|
||||||
DATABASE_HOST,
|
DATABASE_HOST,
|
||||||
@ -21,10 +20,10 @@ class DatabaseManager:
|
|||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
try:
|
try:
|
||||||
self._connection = psycopg2.connect(
|
self._connection = psycopg.connect(
|
||||||
self._connection_uri, cursor_factory=psycopg2.extras.DictCursor
|
self._connection_uri, row_factory=psycopg.rows.dict_row
|
||||||
)
|
)
|
||||||
except psycopg2.OperationalError:
|
except psycopg.OperationalError:
|
||||||
title = "500 Internal Server Error"
|
title = "500 Internal Server Error"
|
||||||
description = "Could not connect to database"
|
description = "Could not connect to database"
|
||||||
raise falcon.HTTPInternalServerError(title, description)
|
raise falcon.HTTPInternalServerError(title, description)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user