-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from rciam/develop
Develop
- Loading branch information
Showing
16 changed files
with
84 additions
and
70 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,38 @@ | ||
from app.utils import configParser | ||
from sqlmodel import create_engine, Session | ||
from sqlalchemy import create_engine | ||
from sqlmodel import Session | ||
from sqlalchemy.exc import OperationalError | ||
|
||
|
||
def get_session(): | ||
# Initialize | ||
config_file = 'config.global.py' | ||
db_params = configParser.getConfig('database_parameters', config_file) | ||
class Database: | ||
def __init__(self): | ||
|
||
url = db_params['database_url'] | ||
pool_size = int(db_params.get('pool_size', 25)) | ||
max_overflow = int(db_params.get('max_overflow', 5)) | ||
engine = create_engine(url, pool_size=pool_size, max_overflow=max_overflow) | ||
config_file = 'config.global.py' | ||
db_params = configParser.getConfig('database_parameters', config_file) | ||
|
||
with Session(engine) as session: | ||
yield session | ||
url = db_params['database_url'] | ||
pool_size = int(db_params.get('pool_size', 25)) | ||
max_overflow = int(db_params.get('max_overflow', 5)) | ||
|
||
self.engine = create_engine(url, pool_size=pool_size, max_overflow=max_overflow) | ||
|
||
def check_database_connection(self): | ||
try: | ||
# Attempt to connect to the database by checking the connection | ||
with self.engine.connect(): | ||
print("Database connection successful!") | ||
return True | ||
except OperationalError as e: | ||
print(f"Database connection failed: {e}") | ||
return False | ||
|
||
def get_session(self): | ||
with Session(self.engine) as session: | ||
yield session | ||
|
||
def create_session(self): | ||
return Session(self.engine) | ||
|
||
|
||
# Creating an instance of Database | ||
db = Database() |
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
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
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
Oops, something went wrong.