diff options
author | Frederick Muriuki Muriithi | 2025-07-31 10:04:16 -0500 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2025-07-31 10:24:19 -0500 |
commit | ea48cd7048854a10c2a305f9d00106077ed317a1 (patch) | |
tree | 0f2d6034d9ccea36343d33bf347546c1a92aba51 /gn_auth/auth/authorisation/resources/inbredset/models.py | |
parent | 1f3e3dc7fc03048e046911ead611afd2d6e1146f (diff) | |
download | gn-auth-ea48cd7048854a10c2a305f9d00106077ed317a1.tar.gz |
Add function to retrieve inbredset-group data.
Diffstat (limited to 'gn_auth/auth/authorisation/resources/inbredset/models.py')
-rw-r--r-- | gn_auth/auth/authorisation/resources/inbredset/models.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/gn_auth/auth/authorisation/resources/inbredset/models.py b/gn_auth/auth/authorisation/resources/inbredset/models.py index 64d41e3..3bc65d2 100644 --- a/gn_auth/auth/authorisation/resources/inbredset/models.py +++ b/gn_auth/auth/authorisation/resources/inbredset/models.py @@ -1,8 +1,10 @@ """Functions to handle the low-level details regarding populations auth.""" from uuid import UUID, uuid4 +from typing import Sequence, Optional import sqlite3 +import gn_auth.auth.db.sqlite3 as db from gn_auth.auth.errors import NotFoundError from gn_auth.auth.authentication.users import User from gn_auth.auth.authorisation.resources.groups.models import Group @@ -94,3 +96,19 @@ def link_data_to_resource(# pylint: disable=[too-many-arguments, too-many-positi "VALUES (:resource_id, :data_link_id)", params) return params + + +def resource_data( + cursor: db.DbCursor, + resource_id: UUID, + offset: int = 0, + limit: Optional[int] = None) -> Sequence[sqlite3.Row]: + """Fetch data linked to a inbred-set resource""" + cursor.execute( + ("SELECT * FROM inbredset_group_resources AS igr " + "INNER JOIN linked_inbredset_groups AS lig " + "ON igr.data_link_id=lig.data_link_id " + "WHERE igr.resource_id=?") + ( + f" LIMIT {limit} OFFSET {offset}" if bool(limit) else ""), + (str(resource_id),)) + return cursor.fetchall() |