Initial MCM project: FastAPI + Textual TUI unified messenger
MultiCustomerMessenger supporting Telegram (python-telegram-bot), WhatsApp (Green API) and SMS (python-gsmmodem-new). REST API with Bearer-token auth, SQLAlchemy models for MariaDB, APScheduler for background polling, and Textual TUI running in same asyncio event-loop. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
38
db/database.py
Normal file
38
db/database.py
Normal file
@@ -0,0 +1,38 @@
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import DeclarativeBase, sessionmaker
|
||||
from sqlalchemy.pool import StaticPool
|
||||
from config import settings
|
||||
|
||||
|
||||
class Base(DeclarativeBase):
|
||||
pass
|
||||
|
||||
|
||||
_connect_args = {}
|
||||
_pool_class = None
|
||||
|
||||
if settings.database_url.startswith("sqlite"):
|
||||
_connect_args = {"check_same_thread": False}
|
||||
_pool_class = StaticPool
|
||||
|
||||
engine = create_engine(
|
||||
settings.database_url,
|
||||
connect_args=_connect_args,
|
||||
**({"poolclass": _pool_class} if _pool_class else {}),
|
||||
echo=settings.debug,
|
||||
)
|
||||
|
||||
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
||||
|
||||
|
||||
def get_db():
|
||||
db = SessionLocal()
|
||||
try:
|
||||
yield db
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
def init_db() -> None:
|
||||
from db import models # noqa: F401 – Modelle müssen importiert sein
|
||||
Base.metadata.create_all(bind=engine)
|
||||
Reference in New Issue
Block a user