コード例 #1
0
 def _query(self, **kwargs):
     try:
         from mongoengine.queryset import Q, QCombination
     except ImportError:
         from mongoengine.queryset.visitor import Q, QCombination
     queries = map(lambda i: Q(**{i[0]: i[1]}), kwargs.items())
     query = QCombination(QCombination.AND, queries)
     return self.connection_model.objects(query)
コード例 #2
0
 def fetch(self, **filters):
     if (len(filters.keys()) > 1):
         queries = map(lambda i: Q(**{i[0]: i[1]}), filters.items())
         query = QCombination(QCombination.AND, queries)
         return DefineMongo.collections[self.collection].objects(
             query).as_pymongo()
     else:
         return DefineMongo.collections[self.collection].objects(
             **filters).as_pymongo()
コード例 #3
0
    def find_user(self, **kwargs):
        try:
            from mongoengine.queryset import Q, QCombination
        except ImportError:
            from mongoengine.queryset.visitor import Q, QCombination
        from mongoengine.errors import ValidationError

        queries = map(lambda i: Q(**{i[0]: i[1]}), kwargs.items())
        query = QCombination(QCombination.AND, queries)
        try:
            return self.user_model.objects(query).first()
        except ValidationError:  # pragma: no cover
            return None
コード例 #4
0
 def fetchOrder(self, **filters):
     if (filters.get("$__order__") == None):
         return self.fetch(**filters)
     else:
         order = filters.pop("$__order__", None)
         temp_limit = filters.pop("$__limit__", None)
         queries = map(lambda i: Q(**{i[0]: i[1]}), filters.items())
         query = QCombination(QCombination.AND, queries)
         if (temp_limit == None):
             return DefineMongo.collections[self.collection].objects(
                 query).order_by(*order).as_pymongo()
         else:
             return DefineMongo.collections[self.collection].objects(
                 query).limit(
                     int(temp_limit)).order_by(*order).as_pymongo()