-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Code Restructure for implementing new features (#29)
* Addded Section for IDE Folders and Files * Changes in Format to adhere to PEP 8 guidelines for Python code * Extracted DB specific logic from core.py into independent files
- Loading branch information
1 parent
f6f305f
commit daafc00
Showing
13 changed files
with
235 additions
and
54 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 |
---|---|---|
|
@@ -14,6 +14,9 @@ build/ | |
# Environment variables | ||
.env | ||
|
||
# IDE | ||
.idea/ | ||
|
||
# Operating system files | ||
.DS_Store | ||
Thumbs.db |
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,4 +1,4 @@ | ||
from .cli import main | ||
|
||
if __name__ == "__main__": | ||
main() | ||
main() |
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
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,38 @@ | ||
import pymysql | ||
|
||
|
||
def connect_to_db(host, user, password, database, port, **kwargs): | ||
""" | ||
Establishes a connection to database using the provided credentials. | ||
Args: | ||
host (str): The hostname or IP address of the server. | ||
user (str): The username to use for the connection. | ||
password (str): The password associated with the username. | ||
database (str): The name of the database to connect to. | ||
port (int): The port number on which the server is listening. Defaults to 3306 if not provided. | ||
Returns: | ||
pymysql.connections.Connection: A connection object to the database. | ||
Raises: | ||
pymysql.MySQLError | ||
""" | ||
return pymysql.connect(host=host, user=user, password=password, database=database, port=port or 3306, **kwargs) | ||
|
||
|
||
def fetch_tables(cursor): | ||
""" | ||
Retrieves the list of tables in the current database. | ||
Args: | ||
cursor (pymysql.cursors.Cursor): Cursor object used to execute SQL queries. | ||
Returns: | ||
list of tuple: A list of tuples where each tuple contains the name of a table in the database. | ||
Raises: | ||
pymysql.MySQLError | ||
""" | ||
cursor.execute("SHOW TABLES") | ||
return cursor.fetchall() |
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,40 @@ | ||
import mysql.connector | ||
|
||
|
||
def connect_to_db(host, user, password, database, port, **kwargs): | ||
""" | ||
Establishes a connection to database using the provided parameters. | ||
Args: | ||
host (str): The hostname or IP address of the server. | ||
user (str): The username to use for the connection. | ||
password (str): The password associated with the username. | ||
database (str): The name of the database to connect to. | ||
port (int): The port number on which the server is listening. Defaults to 3306 if not provided. | ||
Returns: | ||
mysql.connector.MySQLConnection: A MySQL connection object. | ||
Raises: | ||
mysql.connector.Error | ||
""" | ||
return mysql.connector.connect(host=host, user=user, password=password, database=database, port=port or 3306, | ||
**kwargs) | ||
|
||
|
||
def fetch_tables(cursor): | ||
""" | ||
Retrieves the list of tables in the current database. | ||
Args: | ||
cursor (mysql.connector.cursor): Cursor object used to execute SQL queries. | ||
Returns: | ||
list of tuple: A list of tuples where each tuple contains the name of a table in the database. | ||
Raises: | ||
mysql.connector.Error | ||
""" | ||
cursor.execute("SHOW TABLES") | ||
return cursor.fetchall() | ||
|
Oops, something went wrong.