-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Some Refactors in code for compliance.
- Loading branch information
1 parent
46812a6
commit ad3d998
Showing
9 changed files
with
516 additions
and
508 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
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,59 @@ | ||
import logging | ||
from typing import Callable | ||
from .exceptions import ( | ||
AsyncDBException, | ||
) | ||
from .utils import module_exists | ||
|
||
|
||
class AsyncPool: | ||
""" | ||
AsyncPool. | ||
Base class for Asyncio-based DB Pools. | ||
Factory interface for Pool-based connectors. | ||
""" | ||
|
||
_provider: Callable = None | ||
_name: str = "" | ||
|
||
def __new__(cls, provider: str = "dummy", **kwargs) -> Callable: | ||
cls._name = provider | ||
classpath = "asyncdb.providers.{provider}".format(provider=cls._name) | ||
pool = "{}Pool".format(cls._name) | ||
try: | ||
obj = module_exists(pool, classpath) | ||
if obj: | ||
cls._provider = obj(**kwargs) | ||
return cls._provider | ||
else: | ||
raise AsyncDBException( | ||
message="Cannot Load Pool provider {}".format(pool) | ||
) | ||
except Exception as err: | ||
logging.exception(err) | ||
raise | ||
|
||
|
||
class AsyncDB: | ||
"""AsyncDB. | ||
Factory Proxy Interface for Database Providers. | ||
""" | ||
_provider: Callable = None | ||
_name: str = "" | ||
|
||
def __new__(cls, provider: str = "dummy", **kwargs) -> Callable: | ||
cls._name = provider | ||
classpath = "asyncdb.providers.{provider}".format(provider=cls._name) | ||
try: | ||
obj = module_exists(cls._name, classpath) | ||
if obj: | ||
cls._provider = obj(**kwargs) | ||
return cls._provider | ||
else: | ||
raise AsyncDBException( | ||
message="Cannot Load provider {}".format(cls._name) | ||
) | ||
except Exception as err: | ||
logging.exception(err) | ||
raise |
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
Oops, something went wrong.