Skip to content

Commit

Permalink
fix(models) fix model update bug
Browse files Browse the repository at this point in the history
  • Loading branch information
RedmanPlus committed Feb 5, 2023
1 parent 6bd0413 commit 62d9d80
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
Binary file modified .coverage
Binary file not shown.
26 changes: 26 additions & 0 deletions noio_db/models/fields.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from typing import Any

from noio_db.utils.mappings import SQLITE_MAPPINGS


class ID:
def __new__(cls, id_type: Any = int, id_val: Any = None):
self = super().__new__(cls)

self._id_type = id_type
self._id_val = id_val

return self

def __str__(self):
return str(self._id_val)

@property
def sql_definition(self):

sql_type_signature = SQLITE_MAPPINGS.get(self._id_type, False)

if not sql_type_signature:
raise Exception("Can't find matching type signature")

return f"{sql_type_signature} PRIMARY KEY"
4 changes: 2 additions & 2 deletions noio_db/models/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,5 +142,5 @@ def save(self):

if self.Config.is_from_orm:
self.update()

self.insert()
else:
self.insert()
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = noio_db
version = 0.1.0
version = 0.2.0
description = No I/O ORM for the future
author = Anton Rumyantsev
license = MIT
Expand Down

0 comments on commit 62d9d80

Please sign in to comment.