-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6bd0413
commit 62d9d80
Showing
4 changed files
with
29 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -142,5 +142,5 @@ def save(self): | |
|
||
if self.Config.is_from_orm: | ||
self.update() | ||
|
||
self.insert() | ||
else: | ||
self.insert() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters