25 lines
436 B
Python
25 lines
436 B
Python
from sqlalchemy import create_engine
|
|
from sqlalchemy.orm import declarative_base, sessionmaker
|
|
|
|
DATABASE_URL = "mysql+pymysql://root:@localhost/sentiment_slearn"
|
|
|
|
engine = create_engine(
|
|
DATABASE_URL,
|
|
echo=True
|
|
)
|
|
|
|
SessionLocal = sessionmaker(
|
|
autocommit=False,
|
|
autoflush=False,
|
|
bind=engine
|
|
)
|
|
|
|
Base = declarative_base()
|
|
|
|
|
|
def get_db():
|
|
db = SessionLocal()
|
|
try:
|
|
yield db
|
|
finally:
|
|
db.close() |