Skip to content

Commit

Permalink
feat: added dependencies and created clickhouse connectior and sessio…
Browse files Browse the repository at this point in the history
…n developments
  • Loading branch information
fmelihh committed Jul 6, 2024
1 parent ba0f52b commit 31724bb
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 1 deletion.
109 changes: 108 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ coverage = "^7.5.0"
pytest = "^8.2.0"
sqlalchemy = "^2.0.31"
sqlalchemy-clickhouse = "^0.1.5.post0"
alembic = "^1.13.2"


[build-system]
Expand Down
Empty file.
Empty file.
31 changes: 31 additions & 0 deletions src/recommendation_engine/app/core/database/clickhouse.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from loguru import logger
from typing import Iterator

from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, Session
from sqlalchemy.ext.declarative import declarative_base


engine = create_engine("clickhouse+native://default:@localhost/default", future=True)

SessionLocal = sessionmaker(
autocommit=False,
autoflush=False,
bind=engine,
)

ClickhouseBase = declarative_base()


def get_session() -> Iterator[Session]:
db = SessionLocal()
try:
yield db
except Exception as e:
logger.exception(str(e))
db.rollback()
finally:
db.close()


__all__ = ["get_session", "ClickhouseBase"]

0 comments on commit 31724bb

Please sign in to comment.