Skip to content

Commit

Permalink
update connection
Browse files Browse the repository at this point in the history
  • Loading branch information
junanda committed Aug 14, 2021
1 parent ee3d85c commit 524d7e4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ fastapi==0.68.0
uvicorn==0.15.0
python-dotenv==0.19.0
pydantic~=1.8.2
SQLAlchemy~=1.4.22
SQLAlchemy~=1.4.22
PyMySQL==1.0.2
3 changes: 3 additions & 0 deletions utils/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from utils.database import engine
from utils.database import Base
from utils.database import SessionLocal
17 changes: 17 additions & 0 deletions utils/database.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import os
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker

SQLALCHEMY_DATABSE_URL = "mariadb+pymysql://{}:{}@{}/{}?charset=utf8mb4".format(os.getenv('MARIADB_USERNAME'),
os.getenv('MARIADB_PASSWORD'),
os.getenv('MARIADB_HOST'),
os.getenv('DB_NAME'))

engine = create_engine(
SQLALCHEMY_DATABSE_URL, connect_args={"check_same_thread": False}
)

SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)

Base = declarative_base()

0 comments on commit 524d7e4

Please sign in to comment.