def init_db(self): """ Initializes database engine & session. Has to be done on main thread. :return: """ self.db_config = databaseutils.process_db_config(self.config['db']) from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker, scoped_session self.engine = create_engine(self.db_config.constr, pool_recycle=3600) self.session = scoped_session(sessionmaker(bind=self.engine)) # Make sure tables are created DB_Base.metadata.create_all(self.engine)
def init_db(self): """ Initializes database engine & session. :return: """ self.db_config = databaseutils.process_db_config(self.state['db']) from sqlalchemy import create_engine self.engine = create_engine(self.db_config.constr, pool_recycle=3600) from sqlalchemy.orm import sessionmaker self.session = sessionmaker() self.session.configure(bind=self.engine) DB_Base.metadata.create_all(self.engine)
def init_db(self): """ Initializes database engine & session. Has to be done on main thread. :return: """ # sqlite variant: # dbname = 'sqlite:///%s' % self.sqlite_file self.db_config = databaseutils.process_db_config(self.config['db']) self.engine = create_engine(self.db_config.constr, pool_recycle=3600) self.session = scoped_session(sessionmaker(bind=self.engine)) # Make sure tables are created DB_Base.metadata.create_all(self.engine)
def init_db(self): """ Initializes database engine & session. Has to be done on main thread. :return: """ self.db_config = databaseutils.process_db_config(self.config['db']) from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker, scoped_session self.engine = create_engine(self.db_config.constr, pool_recycle=3600) self.session = scoped_session(sessionmaker(bind=self.engine)) # Make sure tables are created DB_Base.metadata.create_all(self.engine) if self.sqlite_file is not None: dbname = 'sqlite:///%s' % self.sqlite_file self.sqlite_engine = create_engine(dbname, echo=False) self.sqlite_session = scoped_session(sessionmaker(bind=self.sqlite_engine)) DB_Base.metadata.create_all(self.sqlite_engine) logger.info('Using SQLite %s' % self.sqlite_engine)