예제 #1
0
 def get_many(self, ids):
     """
         Receives a list of ids and returns a map where the keys are the ids
         and the values are the retrieved objects.
     """
     objects = self._session.query(self.model).filter(self.model.id.in_(ids)).all()
     return {obj.id: _extract_selections(obj, self.model_selections) for obj in objects}
예제 #2
0
 def get(self, id, return_obj=False):
     try:
         obj = self._session.query(self.model).filter(self.model.id == id)\
                                              .first()
         if not return_obj:
             return _extract_selections(obj, self.model_selections)
         return obj
     finally:
         self._session.close()
         db.engine.dispose()
예제 #3
0
 def get_from(self, query, selections=None, return_obj=False):
     """
       Returns a object filtered by a query
     """
     selections = selections or self.model_selections
     try:
         obj = query.first()
         if not return_obj:
             return _extract_selections(obj, selections)
         return obj
     finally:
         self._session.close()
         db.engine.dispose()
예제 #4
0
    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()