def includeme(config): engine = create_datastore(os.getenv(config.registry.settings['mongo_url_env'], 'openrosetta')) session.bind = engine Mapper.compile_all() for mapper in Mapper.all_mappers(): session.ensure_indexes(mapper.collection) config.add_tween('openrosetta.models.ming_autoflush_tween', over=EXCVIEW)
def __call__(self, app, core, config): mainsession.bind = self.mongo_engine Mapper.compile_all() for mapper in Mapper.all_mappers(): mainsession.ensure_indexes(mapper.collection) app = MingMiddleware(app) return app
def things_related_to_project(self, pid): result = [] ac_ids = [ac._id for ac in M.AppConfig.query.find(dict(project_id=pid))] for m in Mapper.all_mappers(): cls = m.mapped_class things = None if 'project_id' in m.property_index: things = cls.query.find(dict(project_id=pid)).all() elif 'app_config_id' in m.property_index: things = cls.query.find(dict(app_config_id={'$in': ac_ids})).all() if things: result.extend(things) return result
def init_db(session): Mapper.compile_all() for mapper in Mapper.all_mappers(): session.ensure_indexes(mapper.collection)