diff options
author | Frederick Muriuki Muriithi | 2024-09-30 15:43:01 -0500 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2024-09-30 15:43:01 -0500 |
commit | 1c3bcf2716ab56ed128c093b17a4adfb857dac11 (patch) | |
tree | f5180f4ffc89ad7a84ad0806bd5fabee8016ca8f /gn_auth/auth/authorisation/resources/base.py | |
parent | a4a241eb15ec0a8338c12660502ab4560240e70d (diff) | |
download | gn-auth-1c3bcf2716ab56ed128c093b17a4adfb857dac11.tar.gz |
Extract function to prevent circular dependencies.
Diffstat (limited to 'gn_auth/auth/authorisation/resources/base.py')
-rw-r--r-- | gn_auth/auth/authorisation/resources/base.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/gn_auth/auth/authorisation/resources/base.py b/gn_auth/auth/authorisation/resources/base.py index ac93049..333ba0d 100644 --- a/gn_auth/auth/authorisation/resources/base.py +++ b/gn_auth/auth/authorisation/resources/base.py @@ -3,6 +3,8 @@ from uuid import UUID from dataclasses import dataclass from typing import Any, Sequence +import sqlite3 + @dataclass(frozen=True) class ResourceCategory: @@ -20,3 +22,15 @@ class Resource: resource_category: ResourceCategory public: bool resource_data: Sequence[dict[str, Any]] = tuple() + + +def resource_from_dbrow(row: sqlite3.Row): + """Convert an SQLite3 resultset row into a resource.""" + return Resource( + resource_id=UUID(row["resource_id"]), + resource_name=row["resource_name"], + resource_category=ResourceCategory( + UUID(row["resource_category_id"]), + row["resource_category_key"], + row["resource_category_description"]), + public=bool(int(row["public"]))) |