34 lines
784 B
Python
34 lines
784 B
Python
"""
|
||
database/core.py
|
||
SQLAlchemy 引擎与 Session 工厂(同步引擎,连接远程 MySQL)。
|
||
"""
|
||
|
||
from __future__ import annotations
|
||
|
||
from sqlalchemy import create_engine
|
||
from sqlalchemy.orm import sessionmaker
|
||
|
||
from config import settings
|
||
|
||
engine = create_engine(
|
||
settings.DATABASE_URL,
|
||
pool_size=settings.DB_POOL_SIZE,
|
||
max_overflow=settings.DB_MAX_OVERFLOW,
|
||
pool_timeout=settings.DB_POOL_TIMEOUT,
|
||
pool_pre_ping=settings.DB_POOL_PRE_PING,
|
||
pool_recycle=3600,
|
||
connect_args={
|
||
"charset": "utf8mb4",
|
||
"use_unicode": True,
|
||
"init_command": "SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci",
|
||
},
|
||
echo=False,
|
||
)
|
||
|
||
SessionLocal = sessionmaker(
|
||
bind=engine,
|
||
autocommit=False,
|
||
autoflush=False,
|
||
expire_on_commit=False,
|
||
)
|