Skip to content

Commit

Permalink
Create db connection string from settings
Browse files Browse the repository at this point in the history
  • Loading branch information
ferhat-mousavi committed Aug 18, 2024
1 parent 7131a9d commit 88bfdd5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
11 changes: 10 additions & 1 deletion data_layer/engine.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from settings.settings import Settings


class Engine:
Expand All @@ -11,7 +12,15 @@ def __new__(cls, *args, **kwargs):
return cls.__instance

def __init__(self):
self.engine = create_engine('sqlite:///db.sqlite3', echo=True)
self.engine = create_engine(self._create_connection_string(), echo=True)
print(self.engine)

self.session = sessionmaker(bind=self.engine)()

def _create_connection_string(self):
settings = Settings()
connection_string = ""
if settings.db_engine == "sqlite":
connection_string = f"{settings.db_engine}:///{settings.db_database_name}"
print("connection_string:", connection_string)
return connection_string
6 changes: 6 additions & 0 deletions settings/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ def db_engine(self):
return self.database.get("engine")
return None

@property
def db_database_name(self):
if self.database:
return self.database.get("database_name")
return None

@property
def md_width(self):
if self.main_display:
Expand Down

0 comments on commit 88bfdd5

Please sign in to comment.