-
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.
Connection
: process pgsql connection param
- Loading branch information
Showing
1 changed file
with
32 additions
and
1 deletion.
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,35 @@ | ||
|
||
import os | ||
import yaml | ||
from contextlib import closing | ||
|
||
from sqlalchemy import create_engine | ||
|
||
class Connection: | ||
def __init__(self, config_param, **kwargs ): | ||
def __init__( | ||
self, | ||
param: str | dict | None = None, | ||
**kwargs | ||
): | ||
|
||
self._param = param or kwargs | ||
self._parse_param() | ||
|
||
|
||
def parse_param(self) -> None: | ||
|
||
self._from_file() | ||
|
||
|
||
def _from_file(self) -> None: | ||
|
||
if isinstance(self._param, str) and os.path.exists(self._param): | ||
|
||
self._param = yaml.load( | ||
closing(open(self._param, 'r')), | ||
Loader = yaml.FullLoader, | ||
) | ||
|
||
def _uri(self) -> str: | ||
|
||
return f'postgresql://' |