Beispiel #1
0
 def get_items_by_category_id(self, cat_id):
     try:
         items_raw = self.session.query(Item).filter_by(cat_id=cat_id)
     except Exception:
         self.session.rollback()
         return None
     finally:
         self.session.close()
     item_schema = ItemSchema(many=True)
     items = item_schema.dump(items_raw).data
     return items
Beispiel #2
0
 def get_item_by_name(self, name):
     try:
         item = self.session.query(Item).filter_by(name=name).one()
     except Exception:
         self.session.rollback()
         return None
     finally:
         self.session.close()
     item_schema = ItemSchema()
     data = item_schema.dump(item).data
     return data
Beispiel #3
0
 def get_all_items(self):
     try:
         items_raw = self.session.query(Item).all()
     except Exception:
         self.session.rollback()
         return None
     finally:
         self.session.close()
     item_schema = ItemSchema(many=True)
     items = item_schema.dump(items_raw).data
     return items
Beispiel #4
0
 def get_item_by_id(self, id):
     try:
         item = self.session.query(Item).filter_by(id=id).one()
         item_schema = ItemSchema()
         data = item_schema.dump(item).data
     except Exception:
         self.session.rollback()
         return None
     finally:
         self.session.close()
     return data
Beispiel #5
0
    def get_latest_items(self, limit):
        try:
            items_raw = self.session.query(Item)\
                .order_by(desc(Item.id))\
                .limit(limit)\
                .all()
        except Exception:
            self.session.rollback()
            return None
        finally:
            self.session.close()

        item_schema = ItemSchema(many=True)
        items = item_schema.dump(items_raw).data
        return items