From 0575e0d9dfeaa59dc00cbd874f3b18de82147c3d Mon Sep 17 00:00:00 2001 From: Amos Amissah <39559758+theonlyamos@users.noreply.github.com> Date: Mon, 9 Sep 2024 16:29:21 +0000 Subject: [PATCH] refactored model.normalise and updated version --- odbms/cli.py | 2 +- odbms/model.py | 19 +++++-------------- setup.py | 2 +- 3 files changed, 7 insertions(+), 16 deletions(-) diff --git a/odbms/cli.py b/odbms/cli.py index 617dbbc..d7ad3c2 100644 --- a/odbms/cli.py +++ b/odbms/cli.py @@ -3,7 +3,7 @@ Database = None -VERSION = "0.3.6" +VERSION = "0.3.7" def start(args): import code diff --git a/odbms/model.py b/odbms/model.py index ca2bfee..4aa4eee 100644 --- a/odbms/model.py +++ b/odbms/model.py @@ -320,7 +320,7 @@ def find_one(cls, params: dict, projection: Union[list,dict] = []): projection.append('id') result = cls.normalise(DBMS.Database.find_one(cls.table_name(), cls.normalise(params, 'params'), projection)) # type: ignore - + return cls(**result) if result else None @classmethod @@ -442,7 +442,7 @@ def json(self)-> dict: def normalise(cls, content: dict|None, optype: str = 'dbresult') -> dict: if content is None: return {} - + if DBMS.Database.dbms == 'mongodb': if optype == 'dbresult': content = dict(content) @@ -456,8 +456,8 @@ def normalise(cls, content: dict|None, optype: str = 'dbresult') -> dict: for key in content.keys(): if key.endswith('_id'): content[key] = ObjectId(content[key]) - elif isinstance(content[key], list): - content[key] = '::'.join(str(v) for v in content[key]) + # elif isinstance(content[key], list): + # content[key] = '::'.join(str(v) for v in content[key]) else: if optype == 'params': if '_id' in content: @@ -477,13 +477,4 @@ def normalise(cls, content: dict|None, optype: str = 'dbresult') -> dict: content[key] = value.split('::') elif key in cls.__fields__ and cls.__fields__[key].type_ is dict: content[key] = json.loads(value) - - try: - return cls(**content).dict() - except ValidationError as e: - print(f"Validation error: {e}") - return content - - @classmethod - def from_orm(cls, obj): - return cls(**cls.normalise(obj)) + return content diff --git a/setup.py b/setup.py index 58687f0..0fe7b4a 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ from importlib.metadata import entry_points from setuptools import setup, find_packages -VERSION = '0.3.6' +VERSION = '0.3.7' with open('README.md', 'rt') as file: description = file.read()