12345678910111213141516171819202122232425 |
- from sqlalchemy import create_engine, MetaData
- from sqlalchemy.orm import sessionmaker, scoped_session
- from sqlalchemy.ext.declarative import declarative_base
- from common import config
- # 定义元数据和命名约定
- POSTGRES_INDEXES_NAMING_CONVENTION = {
- "ix": "ix_%(column_0_label)s",
- "uq": "uq_%(table_name)s_%(column_0_name)s",
- "ck": "ck_%(table_name)s_%(constraint_name)s",
- "fk": "fk_%(table_name)s_%(column_0_name)s",
- "pk": "pk_%(table_name)s"
- }
- metadata = MetaData(naming_convention=POSTGRES_INDEXES_NAMING_CONVENTION)
- # SQLAlchemy 基础设置
- Base = declarative_base(metadata=metadata)
- engine = create_engine(config.DB_URL)
- Session = scoped_session(sessionmaker(bind=engine))
- # 初始化数据库
- def init_db():
- pass
- # Base.metadata.create_all(bind=engine)
|