From f6fcf9cc3ae3d93d59391b3f12843fba3297f0b2 Mon Sep 17 00:00:00 2001 From: Mitsuo Tokumori Date: Sun, 12 Nov 2023 19:37:13 -0500 Subject: Add data and tooltips to student.details --- ustayml/db.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'ustayml/db.py') 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 -- cgit v1.2.3