from sqlalchemy import create_engine from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import sessionmaker from sqlalchemy.pool import NullPool from sqlalchemy.pool import StaticPool from bulkperformancerights import config from bulkperformancerights.models import iterable_base # inject the engine as a dependency instead of having # the conditional logic here? if config.environment in [config.PROD_ENVIRONMENT, config.QA_ENVIRONMENT]: engine = create_engine(config.DB_URL, poolclass=NullPool) elif config.environment == config.DEV_ENVIRONMENT: # seeing the sql commands executed by the ORM is helpful, hence echo engine = create_engine('sqlite:///bulkperformanceupload.db', echo=True) else: engine = create_engine('sqlite://', echo=True) BaseModel = declarative_base(cls=iterable_base.IterableBase) session = sessionmaker(bind=engine, expire_on_commit=False) if config.environment in [config.PROD_ENVIRONMENT, config.QA_ENVIRONMENT]: ar_engine = create_engine(config.AR_DB_URL, poolclass=NullPool) elif config.environment == config.DEV_ENVIRONMENT: # seeing the sql commands executed by the ORM is helpful, hence echo ar_engine = create_engine('sqlite:///art_rel.db', echo=True) else: ar_engine = create_engine('sqlite://', echo=True, connect_args={'check_same_thread': False}, poolclass=StaticPool) ArtRelationsBaseModel = declarative_base(cls=iterable_base.IterableBase) art_relations_session = sessionmaker(bind=ar_engine, expire_on_commit=False)