Migrate Todo CRUD to SQLAlchemy ORM

This commit is contained in:
2026-07-21 16:11:23 +08:00
parent a54364f8f5
commit b50625c606
6 changed files with 207 additions and 118 deletions
+21
View File
@@ -0,0 +1,21 @@
import os
from dotenv import load_dotenv
from sqlalchemy import create_engine
from sqlalchemy.engine import URL
from sqlalchemy.orm import DeclarativeBase
load_dotenv()
class Base(DeclarativeBase):
pass
database_url = URL.create(
drivername = "mysql+pymysql",
username = os.getenv("MYSQL_USER"),
password = os.getenv("MYSQL_PASSWORD"),
host = os.getenv("MYSQL_HOST"),
port = int(os.getenv("MYSQL_PORT")),
database = os.getenv("MYSQL_DATABASE"),
)
engine = create_engine(database_url, pool_pre_ping=True)