2022-01-06 18:30:14 +01:00
|
|
|
import sqlalchemy
|
2021-10-12 14:36:47 +02:00
|
|
|
from sqlalchemy import create_engine
|
|
|
|
from sqlalchemy.orm import scoped_session
|
|
|
|
from sqlalchemy.orm import sessionmaker
|
|
|
|
|
2022-11-02 15:41:48 +01:00
|
|
|
from app import config
|
2021-10-12 14:36:47 +02:00
|
|
|
|
2022-11-02 15:41:48 +01:00
|
|
|
|
|
|
|
engine = create_engine(
|
|
|
|
config.DB_URI, connect_args={"application_name": config.DB_CONN_NAME}
|
|
|
|
)
|
2021-10-12 14:36:47 +02:00
|
|
|
connection = engine.connect()
|
|
|
|
|
|
|
|
Session = scoped_session(sessionmaker(bind=connection))
|
2022-01-06 18:30:14 +01:00
|
|
|
|
|
|
|
# Session is actually a proxy, more info on
|
|
|
|
# https://docs.sqlalchemy.org/en/14/orm/contextual.html?highlight=scoped_session#implicit-method-access
|
|
|
|
Session: sqlalchemy.orm.Session
|