mirror of https://gitee.com/anolis/sysom.git
30 lines
746 B
Python
30 lines
746 B
Python
# -*- coding: utf-8 -*- #
|
|
"""
|
|
Time 2023/11/23 19:11
|
|
Author: mingfeng (SunnyQjm)
|
|
Email mfeng@linux.alibaba.com
|
|
File database.py
|
|
Description:
|
|
"""
|
|
from sqlalchemy import create_engine
|
|
from sqlalchemy.ext.declarative import declarative_base
|
|
from sqlalchemy.orm import sessionmaker
|
|
from conf.settings import SQLALCHEMY_DATABASE_URL
|
|
from sysom_utils import FastApiResponseHelper
|
|
|
|
engine = create_engine(
|
|
SQLALCHEMY_DATABASE_URL, connect_args={}
|
|
)
|
|
|
|
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
|
|
|
def get_db():
|
|
db = SessionLocal()
|
|
try:
|
|
yield db
|
|
finally:
|
|
db.close()
|
|
|
|
Base = declarative_base()
|
|
|
|
FastApiResponseHelper.bind_base_class(Base) |