def _lengen_query(self, query, order_by=None):
     # type: (Query, Optional[InstrumentedAttribute]) -> SizedGenerator
     """
     Given query MUST specify a primary key in oder to fetch all rows. Some DB-APIs will return a random set, which
     must be ordered to return it in a generator.
     """
     if order_by:
         query = query.order_by(order_by)
     count = query.count
     gen = self.__query_yielder(query, self.yield_size)
     return SizedGenerator(gen, count)
 def _get_all2(self, model, order_by, *args):
     # type: (Type[M], InstrumentedAttribute, *BinaryExpression) -> SizedGenerator[M]
     query = self.session.query(model).filter(*args).order_by(
         order_by)  # type: Query
     count = query.count()
     instances = self.__query_yielder(query, self.yield_size)
     lengen = SizedGenerator(instances, count)
     if count > 0:
         return lengen
     elif count == 0:
         return lengen
     else:
         raise NotExistingException("Not Found " + model.__name__ + " by " +
                                    repr(args))
Пример #3
0
 def _get_all(self, exposable_session, model, order_by, **kwargs):
     # type: (ExposableGeneratorQuery, Type[M], InstrumentedAttribute, **Any) -> SizedGenerator[M]
     query = exposable_session.session.query(model).filter_by(
         **kwargs).order_by(order_by)  # type: Query
     count = query.count()
     instances = self.__exposable_query_yielder(exposable_session, query,
                                                self.yield_size)
     lengen = SizedGenerator(instances, count)
     if count > 0:
         return lengen
     elif count == 0:
         return lengen
     else:
         raise NotExistingException("Not Found " + model.__name__ + " by " +
                                    repr(kwargs))