mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-07-19 05:09:40 +02:00
* add basic pre-commit file * add flake8 * add isort * add pep585-upgrade (typing upgrades) * use namespace for import * add mypy * update ci for backend * flake8 scope * fix version format * update makefile * disable strict option (temporary) * fix mypy issues * upgrade type hints (pre-commit) * add vscode typing check * add types to dev deps * remote container draft * update setup script * update compose version * run setup on create * dev containers update * remove unused pages * update setup tips * expose ports * Update pre-commit to include flask8-print (#1053) * Add in flake8-print to pre-commit * pin version of flake8-print * formatting * update getting strated docs * add mypy to pre-commit * purge .mypy_cache on clean * drop mypy Co-authored-by: zackbcom <zackbcom@users.noreply.github.com>
41 lines
875 B
Python
41 lines
875 B
Python
import sqlalchemy as sa
|
|
from sqlalchemy.orm import sessionmaker
|
|
from sqlalchemy.orm.session import Session
|
|
|
|
from mealie.core.config import get_app_settings
|
|
|
|
settings = get_app_settings()
|
|
|
|
|
|
def sql_global_init(db_url: str):
|
|
connect_args = {}
|
|
if "sqlite" in db_url:
|
|
connect_args["check_same_thread"] = False
|
|
|
|
engine = sa.create_engine(
|
|
db_url,
|
|
echo=False,
|
|
connect_args=connect_args,
|
|
pool_pre_ping=True,
|
|
)
|
|
|
|
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
|
|
|
return SessionLocal, engine
|
|
|
|
|
|
SessionLocal, engine = sql_global_init(settings.DB_URL) # type: ignore
|
|
|
|
|
|
def create_session() -> Session:
|
|
global SessionLocal
|
|
return SessionLocal()
|
|
|
|
|
|
def generate_session() -> Session:
|
|
global SessionLocal
|
|
db = SessionLocal()
|
|
try:
|
|
yield db
|
|
finally:
|
|
db.close()
|