-
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.
refactor: enhance database module design
- Loading branch information
Showing
8 changed files
with
32 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from .connection.mssql import MSSQLDatabaseConnection | ||
from .inserter.pandas import PandasSQLDataInserter |
Empty file.
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from .base import DatabaseConnection | ||
|
||
|
||
class MSSQLDatabaseConnection(DatabaseConnection): | ||
"""Concrete implementation for MSSQL database connection.""" | ||
|
||
def __init__( | ||
self, server: str, database: str, username: str, password: str | ||
) -> None: | ||
cnx_string = ( | ||
f"mssql+pyodbc://{username}:{password}@" | ||
f"{server}/{database}?driver=ODBC+Driver+17+for+SQL+Server" | ||
) | ||
super().__init__(cnx_string) |
Empty file.
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import pandas as pd | ||
|
||
from ..connection.base import DatabaseConnection | ||
|
||
|
||
class DataInserter: | ||
"""Abstracts the data insertion to a database.""" | ||
|
||
def __init__(self, db_connection: DatabaseConnection): | ||
self.db_connection = db_connection | ||
|
||
def insert(self, df: pd.DataFrame, table_name: str): | ||
raise NotImplementedError("Subclasses must implement this method.") |
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