Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat - duckdb #19

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions src/aloha/db/duckdb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
__all__ = ('DuckOperator',)

import duckdb
from sqlalchemy import create_engine
from sqlalchemy.sql import text

from ..logger import LOG

LOG.debug('duckdb: duckdb version = %s' % duckdb.__version__)


class DuckOperator:
def __init__(self, db_config, **kwargs):
self._config = {
'path': db_config['path'],
'dbname': db_config['dbname'],
}
connect_args = {}
if 'schema' in db_config:
connect_args['options'] = '-csearch_path={}'.format(db_config['schema'])

try:
self.engine = create_engine(
'postgresql+psycopg2://{user}:{password}@{host}:{port}/{dbname}'.format(**self._config),
connect_args=connect_args, client_encoding='utf8', encoding='utf-8',
pool_size=20, max_overflow=10, pool_pre_ping=True, **kwargs
)
LOG.debug("PostgresSQL connected: {host}:{port}/{dbname}".format(**self._config))
except Exception as e:
LOG.error(e)
raise RuntimeError('Failed to connect to PostgresSQL')

@property
def connection(self):
return self.engine

def execute_query(self, sql, *args, **kwargs):
with self.engine.connect() as conn:
cur = conn.execute(text(sql), *args, **kwargs)
return cur

@property
def connection_str(self) -> str:
return "duckdb:///{user}:{password}@{host}:{port}/{dbname}".format(**self._config)
2 changes: 1 addition & 1 deletion src/aloha/db/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from .base import PasswordVault
from ..logger import LOG

LOG.debug('postgres: psycopg2 version = %s' % psycopg2.__version__)
LOG.debug('postgres: psycopg version = %s' % psycopg2.__version__)


class PostgresOperator:
Expand Down
16 changes: 12 additions & 4 deletions src/aloha/script/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,19 @@ def build(base: str = None, dist: str = 'build', exclude: list = None, keep: lis
for dir_path, dir_names, file_names in os.walk(path_base):
dir_name = dir_path.split(os.sep)[-1] # name of the current directory

if dir_path.startswith(path_build) or dir_path in files_exclude:
continue # skip: folder for build output, and excluded folders

flag_skip: bool = False
if dir_name.startswith('.') or (os.sep + '.' in dir_path):
continue # hidden folders and sub-folders
flag_skip = True # hidden folders and sub-folders
elif dir_path.startswith(path_build):
flag_skip = True # skip: folder for build output, and excluded folders
else:
for f in files_exclude:
if dir_path.startswith(f):
flag_skip = True
break

if flag_skip:
continue

for file in file_names:
(name, extension), path = os.path.splitext(file), os.path.join(dir_path, file)
Expand Down