def retrieve_aql_documents(big_collection): """ """ all_aql_query = Query() all_aql_query.append_collection(collection_name=big_collection.name) all_aql_query.execute()
def test_lower_equals_filtering(self): q = Query() q.append_collection(self.test_1_col.name) q.filter(little_number__lte=3) docs = q.execute() self.assertEqual(len(docs), 2)
def test_lower_filtering(self): q = Query() q.append_collection(self.test_1_col.name) q.filter(little_number__lt=3) docs = q.execute() self.assertEqual(len(docs), 1) self.assertDocumentsEqual(self.col1_doc2, docs[0])
def test_filter_number_field_in_document(self): q = Query() q.append_collection(self.test_1_col.name) q.filter(little_number=self.col1_doc3.little_number) docs = q.execute() self.assertEqual(len(docs), 1) doc = docs[0] self.assertDocumentsEqual(doc, self.col1_doc3)
def test_filter_string_field_in_document(self): q = Query() q.append_collection(self.test_1_col.name) q.filter(small_text=self.col1_doc2.small_text) docs = q.execute() self.assertEqual(len(docs), 1) doc = docs[0] self.assertDocumentsEqual(doc, self.col1_doc2)
def test_filter_string_field_in_document(self): q = Query() q.append_collection(self.test_1_col.name) q.filter(small_text=self.col1_doc2.small_text) docs = q.execute() self.assertEqual(len(docs), 1) doc = docs[0] self.assertDocumentsEqual(doc, self.col1_doc2)
def test_filter_number_field_in_document(self): q = Query() q.append_collection(self.test_1_col.name) q.filter(little_number=self.col1_doc3.little_number) docs = q.execute() self.assertEqual(len(docs), 1) doc = docs[0] self.assertDocumentsEqual(doc, self.col1_doc3)
def test_icontains_filtering(self): q = Query() q.append_collection(self.test_1_col.name) q.filter(small_text__icontains='LL') docs = q.execute() self.assertEqual(len(docs), 1) doc1 = docs[0] self.assertDocumentsEqual(doc1, self.col1_doc1)
def test_exclude_document_from_list(self): q = Query() q.append_collection(self.test_1_col.name) q.exclude(loved=False) docs = q.execute() self.assertEqual(len(docs), 1) doc1 = docs[0] self.assertDocumentsEqual(doc1, self.col1_doc3)
def test_exclude_document_from_list(self): q = Query() q.append_collection(self.test_1_col.name) q.exclude(loved=False) docs = q.execute() self.assertEqual(len(docs), 1) doc1 = docs[0] self.assertDocumentsEqual(doc1, self.col1_doc3)
def test_limit_with_start_simple_list(self): q = Query() q.append_collection(self.test_1_col.name) q.order_by('little_number') q.limit(count=1, start=1) docs = q.execute() self.assertEqual(len(docs), 1) doc1 = docs[0] self.assertDocumentsEqual(doc1, self.col1_doc3)
def test_sorting_asc_document_list(self): q = Query() q.append_collection(self.test_1_col.name) q.order_by('little_number') docs = q.execute() self.assertEqual(len(docs), 3) doc1 = docs[0] doc2 = docs[1] doc3 = docs[2] self.assertDocumentsEqual(doc1, self.col1_doc2) self.assertDocumentsEqual(doc2, self.col1_doc3) self.assertDocumentsEqual(doc3, self.col1_doc1)
def test_sorting_asc_document_list(self): q = Query() q.append_collection(self.test_1_col.name) q.order_by('little_number') docs = q.execute() self.assertEqual(len(docs), 3) doc1 = docs[0] doc2 = docs[1] doc3 = docs[2] self.assertDocumentsEqual(doc1, self.col1_doc2) self.assertDocumentsEqual(doc2, self.col1_doc3) self.assertDocumentsEqual(doc3, self.col1_doc1)
def test_filter_from_multiple_collections(self): q = Query() q.append_collection(self.test_1_col.name) q.append_collection(self.test_2_col.name) dynamic_filter_dict = {} col_1_filter_name = "%s__%s" % (self.test_1_col.name, "little_number") col_2_filter_name = "%s__%s" % (self.test_2_col.name, "little_number") dynamic_filter_dict[col_1_filter_name] = 33 dynamic_filter_dict[col_2_filter_name] = 33 q.filter(bit_operator=Query.OR_BIT_OPERATOR, **dynamic_filter_dict) docs = q.execute() self.assertEqual(len(docs), 2) doc1 = docs[0] doc2 = docs[1] self.assertNotEqual(doc1.id, doc2.id) self.assertEqual(doc1.little_number, 33) self.assertEqual(doc2.little_number, 33)
def test_filter_from_multiple_collections(self): q = Query() q.append_collection(self.test_1_col.name) q.append_collection(self.test_2_col.name) dynamic_filter_dict = {} col_1_filter_name = "%s__%s" % (self.test_1_col.name, "little_number") col_2_filter_name = "%s__%s" % (self.test_2_col.name, "little_number") dynamic_filter_dict[col_1_filter_name] = 33 dynamic_filter_dict[col_2_filter_name] = 33 q.filter(bit_operator=Query.OR_BIT_OPERATOR, **dynamic_filter_dict) docs = q.execute() self.assertEqual(len(docs), 2) doc1 = docs[0] doc2 = docs[1] self.assertNotEqual(doc1.id, doc2.id) self.assertEqual(doc1.little_number, 33) self.assertEqual(doc2.little_number, 33)
def test_get_all_doc_from_1_collection(self): q = Query() q.append_collection(self.test_2_col.name) docs = q.execute() self.assertEqual(len(docs), 2)
class CollectionQueryset(object): """ """ def __init__(self, manager): """ """ self._manager = manager self._collection = manager._model_class.collection_instance self._query = Query() # Relations self._is_working_on_relations = False self._relations_start_model = None self._relations_end_model = None self._relations_relation_collection = None self._related_model_class = None # Cache self._has_cache = False self._cache = [] def get_field_relations(self, relation_collection, related_model_class, start_model=None, end_model=None): """ """ self._is_working_on_relations = True self._has_cache = False self._relations_start_model = start_model self._relations_end_model = end_model self._relations_relation_collection = relation_collection self._related_model_class = related_model_class return self def all(self): """ """ self._has_cache = False self._query.set_collection(self._collection.name) self._query.clear() return self def filter(self, bit_operator=Query.NO_BIT_OPERATOR, **kwargs): """ """ self._has_cache = False self._query.filter(bit_operator=bit_operator, **kwargs) return self def exclude(self, **kwargs): """ """ self._has_cache = False self._query.exclude(**kwargs) return self def limit(self, count, start=-1): """ """ self._has_cache = False self._query.limit(count, start) return self def order_by(self, field, order): """ """ self._has_cache = False self._query.order_by(field=field, order=order) return self def _clone(self): """ """ cloned_queryset = CollectionQueryset(manager=self._manager) # Query cloned_queryset._query = copy.deepcopy(self._query) # Relation cloned_queryset._is_working_on_relations = self._is_working_on_relations cloned_queryset._relations_start_model = self._relations_start_model cloned_queryset._relations_end_model = self._relations_end_model cloned_queryset._relations_relation_collection = self._is_working_on_relations cloned_queryset._related_model_class = self._related_model_class return cloned_queryset def _generate_cache(self): """ """ self._cache = [] # TODO: Check how to best clear this list self._has_cache = True if self._is_working_on_relations: start_model = self._relations_start_model end_model = self._relations_end_model relation_collection = self._relations_relation_collection if start_model: found_relations = Traveser.follow( start_vertex=start_model.document.id, edge_collection=relation_collection, direction='outbound' ) else: found_relations = Traveser.follow( start_vertex=end_model.document.id, edge_collection=relation_collection, direction='inbound' ) result = found_relations result_class = self._related_model_class else: result = self._query.execute() result_class = self._manager._model_class for doc in result: model = self._manager._create_model_from_doc(doc=doc, model_class=result_class) self._cache.append(model) def __getitem__(self, item): """ Is used for the index access """ if not self._has_cache: self._generate_cache() return self._cache[item] def __len__(self): """ """ if not self._has_cache: self._generate_cache() return len(self._cache)
def test_get_all_doc_from_1_collection(self): q = Query() q.append_collection(self.test_2_col.name) docs = q.execute() self.assertEqual(len(docs), 2)
class CollectionQueryset(LazyQueryset): """ """ def __init__(self, manager): """ """ super(CollectionQueryset, self).__init__(manager=manager) self._query = Query() # Relations self._is_working_on_relations = False self._relations_start_model = None self._relations_end_model = None self._relations_relation_collection = None self._related_model_class = None def get_field_relations(self, relation_collection, related_model_class, start_model=None, end_model=None): """ """ self._is_working_on_relations = True self._has_cache = False self._relations_start_model = start_model self._relations_end_model = end_model self._relations_relation_collection = relation_collection self._related_model_class = related_model_class return self def get(self, **kwargs): """ """ return self._manager.get(**kwargs) def all(self): """ """ self._has_cache = False self._query.set_collection(self._collection.name) self._query.clear() return self def filter(self, bit_operator=Query.NO_BIT_OPERATOR, **kwargs): """ """ self._has_cache = False kwargs = self._normalize_kwargs(**kwargs) self._query.filter(bit_operator=bit_operator, **kwargs) return self def exclude(self, **kwargs): """ """ self._has_cache = False kwargs = self._normalize_kwargs(**kwargs) self._query.exclude(**kwargs) return self def limit(self, count, start=-1): """ """ self._has_cache = False self._query.limit(count, start) return self def order_by(self, field, order): """ """ self._has_cache = False self._query.order_by(field=field, order=order) return self def _normalize_kwargs(self, **kwargs): """ """ # You can use this way models for key, value in list(kwargs.items()): if isinstance(value, CollectionModel): kwargs[key] = value.id return kwargs def _clone(self): """ """ cloned_queryset = CollectionQueryset(manager=self._manager) # Query cloned_queryset._query = copy.deepcopy(self._query) # Relation cloned_queryset._is_working_on_relations = self._is_working_on_relations cloned_queryset._relations_start_model = self._relations_start_model cloned_queryset._relations_end_model = self._relations_end_model cloned_queryset._relations_relation_collection = self._is_working_on_relations cloned_queryset._related_model_class = self._related_model_class return cloned_queryset def _generate_cache(self): """ """ super(CollectionQueryset, self)._generate_cache() if self._is_working_on_relations: start_model = self._relations_start_model end_model = self._relations_end_model relation_collection = self._relations_relation_collection if start_model: found_relations = Traveser.follow( start_vertex=start_model.document.id, edge_collection=relation_collection, direction='outbound') else: found_relations = Traveser.follow( start_vertex=end_model.document.id, edge_collection=relation_collection, direction='inbound') result = found_relations result_class = self._related_model_class else: result = self._query.execute() result_class = self._manager._model_class for doc in result: model = self._manager._create_model_from_doc( doc=doc, model_class=result_class) self._cache.append(model)
class CollectionQueryset(object): """ """ def __init__(self, manager): """ """ self._manager = manager self._collection = manager._model_class.collection_instance self._query = Query() # Relations self._is_working_on_relations = False self._relations_start_model = None self._relations_end_model = None self._relations_relation_collection = None self._related_model_class = None # Cache self._has_cache = False self._cache = [] def get_field_relations(self, relation_collection, related_model_class, start_model=None, end_model=None): """ """ self._is_working_on_relations = True self._has_cache = False self._relations_start_model = start_model self._relations_end_model = end_model self._relations_relation_collection = relation_collection self._related_model_class = related_model_class return self def all(self): """ """ self._has_cache = False self._query.set_collection(self._collection.name) self._query.clear() def filter(self, bit_operator=Query.NO_BIT_OPERATOR, **kwargs): """ """ self._has_cache = False self._query.filter(bit_operator=bit_operator, **kwargs) def exclude(self, **kwargs): """ """ self._has_cache = False self._query.exclude(**kwargs) def limit(self, count, start=-1): """ """ self._has_cache = False self._query.limit(count, start) def _clone(self): """ """ cloned_queryset = CollectionQueryset(manager=self._manager) # Query cloned_queryset._query = copy.deepcopy(self._query) # Relation cloned_queryset._is_working_on_relations = self._is_working_on_relations cloned_queryset._relations_start_model = self._relations_start_model cloned_queryset._relations_end_model = self._relations_end_model cloned_queryset._relations_relation_collection = self._is_working_on_relations cloned_queryset._related_model_class = self._related_model_class return cloned_queryset def _generate_cache(self): """ """ self._cache = [] # TODO: Check how to best clear this list self._has_cache = True if self._is_working_on_relations: start_model = self._relations_start_model end_model = self._relations_end_model relation_collection = self._relations_relation_collection if start_model: found_relations = Traveser.follow( start_vertex=start_model.document.id, edge_collection=relation_collection, direction='outbound') else: found_relations = Traveser.follow( start_vertex=end_model.document.id, edge_collection=relation_collection, direction='inbound') result = found_relations result_class = self._related_model_class else: result = self._query.execute() result_class = self._manager._model_class for doc in result: model = self._manager._create_model_from_doc( doc=doc, model_class=result_class) self._cache.append(model) def __getitem__(self, item): """ Is used for the index access """ if not self._has_cache: self._generate_cache() return self._cache[item] def __len__(self): """ """ if not self._has_cache: self._generate_cache() return len(self._cache)
class CollectionQueryset(LazyQueryset): """ """ def __init__(self, manager): """ """ super(CollectionQueryset, self).__init__(manager=manager) self._query = Query() # Relations self._is_working_on_relations = False self._relations_start_model = None self._relations_end_model = None self._relations_relation_collection = None self._related_model_class = None def get_field_relations(self, relation_collection, related_model_class, start_model=None, end_model=None): """ """ self._is_working_on_relations = True self._has_cache = False self._relations_start_model = start_model self._relations_end_model = end_model self._relations_relation_collection = relation_collection self._related_model_class = related_model_class return self def get(self, **kwargs): """ """ return self._manager.get(**kwargs) def all(self): """ """ self._has_cache = False self._query.set_collection(self._collection.name) self._query.clear() return self def filter(self, bit_operator=Query.NO_BIT_OPERATOR, **kwargs): """ """ self._has_cache = False kwargs = self._normalize_kwargs(**kwargs) self._query.filter(bit_operator=bit_operator, **kwargs) return self def exclude(self, **kwargs): """ """ self._has_cache = False kwargs = self._normalize_kwargs(**kwargs) self._query.exclude(**kwargs) return self def limit(self, count, start=-1): """ """ self._has_cache = False self._query.limit(count, start) return self def order_by(self, field, order): """ """ self._has_cache = False self._query.order_by(field=field, order=order) return self def _normalize_kwargs(self, **kwargs): """ """ # You can use this way models for key, value in kwargs.items(): if isinstance(value, CollectionModel): kwargs[key] = value.id return kwargs def _clone(self): """ """ cloned_queryset = CollectionQueryset(manager=self._manager) # Query cloned_queryset._query = copy.deepcopy(self._query) # Relation cloned_queryset._is_working_on_relations = self._is_working_on_relations cloned_queryset._relations_start_model = self._relations_start_model cloned_queryset._relations_end_model = self._relations_end_model cloned_queryset._relations_relation_collection = self._is_working_on_relations cloned_queryset._related_model_class = self._related_model_class return cloned_queryset def _generate_cache(self): """ """ super(CollectionQueryset, self)._generate_cache() if self._is_working_on_relations: start_model = self._relations_start_model end_model = self._relations_end_model relation_collection = self._relations_relation_collection if start_model: found_relations = Traveser.follow( start_vertex=start_model.document.id, edge_collection=relation_collection, direction='outbound' ) else: found_relations = Traveser.follow( start_vertex=end_model.document.id, edge_collection=relation_collection, direction='inbound' ) result = found_relations result_class = self._related_model_class else: result = self._query.execute() result_class = self._manager._model_class for doc in result: model = self._manager._create_model_from_doc(doc=doc, model_class=result_class) self._cache.append(model)
class CollectionQueryset(object): """ """ def __init__(self, manager): """ """ self._manager = manager self._collection = manager._model_class.collection_instance self._query = Query() # Cache self._has_cache = False self._cache = [] def all(self): """ """ self._has_cache = False self._query.set_collection(self._collection.name) self._query.clear() def filter(self, bit_operator=Query.NO_BIT_OPERATOR, **kwargs): """ """ self._has_cache = False self._query.filter(bit_operator=bit_operator, **kwargs) def exclude(self, **kwargs): """ """ self._has_cache = False self._query.exclude(**kwargs) def limit(self, count, start=-1): """ """ self._has_cache = False self._query.limit(count, start) def _generate_cache(self): """ """ self._cache = [] # TODO: Check how to best clear this list self._has_cache = True result = self._query.execute() for doc in result: model = self._manager._create_model_from_doc(doc=doc) self._cache.append(model) def __getitem__(self, item): """ Is used for the index access """ if not self._has_cache: self._generate_cache() return self._cache[item] def __len__(self): """ """ if not self._has_cache: self._generate_cache() return len(self._cache)