car/db/mysql.py

22 lines
461 B
Python
Raw Normal View History

2023-05-31 11:52:34 +08:00
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
engine = create_engine('mysql+pymysql://', connect_args={
'user': "root",
'password': "12341234",
'host': '10.10.10.200',
'port': 3306,
'database': 'car',
'charset': 'utf8mb4'
})
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
def database():
_db = SessionLocal()
try:
yield _db
finally:
_db.close()