aboutsummaryrefslogtreecommitdiff
path: root/ustayml/db.py
diff options
context:
space:
mode:
Diffstat (limited to 'ustayml/db.py')
-rw-r--r--ustayml/db.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/ustayml/db.py b/ustayml/db.py
index 25d0188..04587cc 100644
--- a/ustayml/db.py
+++ b/ustayml/db.py
@@ -57,12 +57,18 @@ def init_app(app):
# Helper functions
-def get_paginated_items(query: str, params: list=[], pagination: dict={}):
+def get_paginated_rows(query: str, params: list=[], pagination: dict={}):
limit = pagination.get('pagesize', 100)
offset = pagination.get('page', 0) * limit
with get_db().cursor() as cursor:
cursor.execute(f"{query} LIMIT %s OFFSET %s;", params + [limit, offset])
pagination['n_pages'] = math.ceil(cursor.rowcount / limit)
pagination['rowcount'] = cursor.rowcount
- items = cursor.fetchall()
- return items \ No newline at end of file
+ rows = cursor.fetchall()
+ return rows
+
+def get_row(query: str, params: list=[]):
+ with get_db().cursor() as cursor:
+ cursor.execute(query, params)
+ row = cursor.fetchone()
+ return row \ No newline at end of file