Skip to content

Commit

Permalink
Add mysql connection module
Browse files Browse the repository at this point in the history
- include sqlalchemy engine for pandas
  • Loading branch information
ajparsons committed Oct 1, 2024
1 parent 4e54fbd commit e2c772f
Show file tree
Hide file tree
Showing 3 changed files with 195 additions and 1 deletion.
160 changes: 159 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 @@ -15,6 +15,7 @@ mysqlclient = "2.2.4"
pyyaml = "6.0.1"
commonlib = {path = "commonlib"}
pydantic = "^2.8.2"
sqlalchemy = "^2.0.32"


[tool.poetry.group.dev.dependencies]
Expand Down
35 changes: 35 additions & 0 deletions src/twfy_tools/db/connection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""
Basic database connection for TheyWorkForYou database.
"""

from typing import cast

import MySQLdb
from sqlalchemy import URL, create_engine

from ..common.config import config


def get_twfy_db_connection() -> MySQLdb.Connection:
db_connection = cast(
MySQLdb.Connection,
MySQLdb.connect(
host=config.TWFY_DB_HOST,
db=config.TWFY_DB_NAME,
user=config.TWFY_DB_USER,
passwd=config.TWFY_DB_PASS,
charset="utf8",
),
)
return db_connection


engine = create_engine(
URL.create(
drivername="mysql+mysqldb",
username=config.TWFY_DB_USER,
password=config.TWFY_DB_PASS,
host=config.TWFY_DB_HOST,
database=config.TWFY_DB_NAME,
)
)

0 comments on commit e2c772f

Please sign in to comment.