def get(self, id): try: obj = self._session.query(self.model).filter(self.model.id == id)\ .first() return _extract_selections(obj, self.model_selections) finally: self._session.close() db.engine.dispose()
def filter_by_id(self, recipe_id): obj = self._session.query(Recipe)\ .filter(self.model.id == recipe_id).first() selections = _extract_selections(obj, self.model_selections) self._session.close() return selections
def _list(self, model=None, selections=None, limit=50, query=None): model = model or self.model selections = selections or self.model_selections if query is None: query = self._session.query(model) if limit is not None: query = query.limit(limit) try: objects = query.all() return _extract_selections(objects, selections) finally: self._session.close() db.engine.dispose()