Skip to content

Commit

Permalink
refactored model.normalise and updated version
Browse files Browse the repository at this point in the history
  • Loading branch information
theonlyamos committed Sep 9, 2024
1 parent d4c6555 commit 0575e0d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 16 deletions.
2 changes: 1 addition & 1 deletion odbms/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

Database = None

VERSION = "0.3.6"
VERSION = "0.3.7"

def start(args):
import code
Expand Down
19 changes: 5 additions & 14 deletions odbms/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand All @@ -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
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -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()
Expand Down

0 comments on commit 0575e0d

Please sign in to comment.