diff options
| author | Mitsuo Tokumori <rtokumori@pucp.edu.pe> | 2023-11-12 19:37:13 -0500 |
|---|---|---|
| committer | Mitsuo Tokumori <rtokumori@pucp.edu.pe> | 2023-11-12 19:37:13 -0500 |
| commit | f6fcf9cc3ae3d93d59391b3f12843fba3297f0b2 (patch) | |
| tree | 289032ff9b133a9fe71e8a23355fdea10171bcf6 /ustayml/db.py | |
| parent | fcd9465d564b08ae289417fb0616942b38fd0836 (diff) | |
Add data and tooltips to student.details
Diffstat (limited to 'ustayml/db.py')
| -rw-r--r-- | ustayml/db.py | 12 |
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 |
