-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.py
More file actions
20 lines (15 loc) · 742 Bytes
/
Copy pathdatabase.py
File metadata and controls
20 lines (15 loc) · 742 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from __future__ import annotations
import os
from pathlib import Path
from sqlalchemy import create_engine
from sqlalchemy.orm import declarative_base, sessionmaker
CLOUD_DIR = Path(__file__).resolve().parents[1]
DEFAULT_SQLITE_PATH = CLOUD_DIR / "data" / "fpgawand.sqlite3"
DEFAULT_SQLITE_PATH.parent.mkdir(parents=True, exist_ok=True)
DATABASE_URL = os.getenv("DATABASE_URL", f"sqlite:///{DEFAULT_SQLITE_PATH}")
_ENGINE_KWARGS = {"echo": False, "future": True}
if DATABASE_URL.startswith("sqlite"):
_ENGINE_KWARGS["connect_args"] = {"check_same_thread": False}
engine = create_engine(DATABASE_URL, **_ENGINE_KWARGS)
SessionLocal = sessionmaker(bind=engine, autoflush=False, autocommit=False, future=True)
Base = declarative_base()