-
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.
new(project) Add insert factory, insert method to the model and some …
…utils
- Loading branch information
1 parent
93d9d11
commit eaf6480
Showing
15 changed files
with
158 additions
and
68 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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
/__pycache__ | ||
/venv | ||
*.pyc | ||
*.egg-info/ | ||
*.egg-info/ | ||
main.py |
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
31 changes: 31 additions & 0 deletions
31
noio_db/core/sql_object_factories/insert_sql_object_factory.py
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,31 @@ | ||
from noio_db.core.sql_object_factories import AbstractSQLObjectFactory | ||
from noio_db.core.sql_objects import ( | ||
ArgInBracesSQLObject, | ||
BaseSQLObject, | ||
InsertSQLObject, | ||
) | ||
from noio_db.utils import list_into_comma_sql_object | ||
|
||
|
||
class InsertSQLObjectFactory(AbstractSQLObjectFactory): | ||
def get_object(self, *args) -> BaseSQLObject: | ||
|
||
if len(args) < 3: | ||
raise Exception( | ||
f"Must have at least 3 args for the insert factoty, got {len(args)}" | ||
) | ||
|
||
destination = args[0] | ||
|
||
field_mappings = ArgInBracesSQLObject(list_into_comma_sql_object(*args[1])) | ||
|
||
values = [] | ||
|
||
for val_group in args[2:]: | ||
|
||
val_mappings = ArgInBracesSQLObject(list_into_comma_sql_object(*val_group)) | ||
values.append(val_mappings) | ||
|
||
values = list_into_comma_sql_object(*values) | ||
|
||
return InsertSQLObject(destination, field_mappings, values) |
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
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
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
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,5 @@ | ||
class IDField: | ||
def __init__(self, parent): | ||
self.__counter__ = 1 | ||
self.parent = parent | ||
self.parent_id = self.__counter__ |
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
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
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 |
---|---|---|
@@ -1,2 +1,8 @@ | ||
from noio_db.utils.arg_manipulation import pair_up_args, zip_into_dict | ||
from noio_db.utils.arg_manipulation import ( | ||
list_into_comma_sql_object, | ||
pair_up_args, | ||
zip_into_dict, | ||
) | ||
from noio_db.utils.async_decorator import ToAsync | ||
from noio_db.utils.get_settings import get_current_settings | ||
from noio_db.utils.mappings import SQLITE_MAPPINGS |
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
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,24 @@ | ||
from inspect import currentframe, getouterframes | ||
|
||
|
||
class ToAsync: | ||
def __init__(self, func): | ||
self.func = func | ||
|
||
async def _run_async(self, *args, **kwargs): | ||
|
||
return self.func(*args, **kwargs) | ||
|
||
def _run_sync(self, *args, **kwargs): | ||
|
||
return self.func(*args, **kwargs) | ||
|
||
def __call__(self, *args, **kwargs): | ||
|
||
curframe = currentframe() | ||
outframe = getouterframes(curframe, 1) | ||
|
||
if "await" in outframe[1][4][0]: | ||
return self._run_async(*args, **kwargs) | ||
|
||
return self._run_sync(*args, **kwargs) |
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 |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
"_from", | ||
"_group_by", | ||
"_order_by", | ||
"_insert", | ||
} | ||
|
||
KWARG_METHOD_NAMES = { | ||
|
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,13 @@ | ||
from importlib import import_module | ||
|
||
from noio_db.core.db_drivers import BaseDriver | ||
from noio_db.settings import Settings | ||
|
||
|
||
def get_current_settings(obj) -> BaseDriver: | ||
if user_settings := Settings.__subclasses__(): | ||
return import_module(user_settings[0]().driver_path).Driver( | ||
obj, user_settings[0]() | ||
) | ||
|
||
return import_module(Settings().driver_path).Driver(obj, Settings()) |
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