lesia_db.py
934 Bytes
import sys
from flask import current_app
from sqlalchemy import create_engine
from sqlalchemy.exc import OperationalError
from sqlalchemy.ext.automap import automap_base
from sqlalchemy.orm import Session
lesia_base = automap_base()
engine = create_engine(current_app.config['LESIA_AGENTS_DB_URI'])
# reflect the tables
try:
lesia_base.prepare(engine, reflect=True)
except OperationalError:
current_app.logger.error("Please, configure the mysql database (see db_config.py)")
sys.exit(-1)
lesia_session = Session(engine)
# mapped classes are now created with names by default
# matching that of the table name.
lesia_agent = lesia_base.classes.agent
lesia_service = lesia_base.classes.gestit_services
lesia_project = lesia_base.classes.gestit_projets
lesia_fonction = lesia_base.classes.gestit_fonctions
lesia_affectation = lesia_base.classes.gestit_affectations
lesia_periods = lesia_base.classes.gestit_semestres