88cf6458d0
Application web d'inventaire réseau manuel avec FastAPI, Vue 3 et Docker. Inclut l'authentification JWT, la découverte ICMP, et la topologie en cards CSS. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
36 lines
820 B
Python
36 lines
820 B
Python
import sqlite3
|
|
|
|
from sqlalchemy import create_engine, event
|
|
from sqlalchemy.engine import Engine
|
|
from sqlalchemy.orm import sessionmaker, declarative_base
|
|
import os
|
|
|
|
os.makedirs("data", exist_ok=True)
|
|
|
|
_DATABASE_URL = os.environ.get("DATABASE_URL", "sqlite:///./data/topology.db")
|
|
|
|
engine = create_engine(
|
|
_DATABASE_URL,
|
|
connect_args={"check_same_thread": False}
|
|
)
|
|
|
|
|
|
@event.listens_for(Engine, "connect")
|
|
def _set_sqlite_pragma(dbapi_conn, _record):
|
|
if isinstance(dbapi_conn, sqlite3.Connection):
|
|
cursor = dbapi_conn.cursor()
|
|
cursor.execute("PRAGMA foreign_keys=ON")
|
|
cursor.close()
|
|
|
|
|
|
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
|
Base = declarative_base()
|
|
|
|
|
|
def get_db():
|
|
db = SessionLocal()
|
|
try:
|
|
yield db
|
|
finally:
|
|
db.close()
|