# Path: dockit/backends/queryset.py
# class QuerySet(object):
#     '''
#     Acts as a caching layer around an implemented `BaseDocumentQuery`
#     TODO: implement actual caching
#     '''
#     def __init__(self, query):
#         self.query = query
#     
#     @property
#     def document(self):
#         return self.query.document
#     
#     def __len__(self):
#         #TODO cache
#         return self.query.__len__()
#     
#     def count(self):
#         return self.__len__()
#     
#     def delete(self):
#         return self.query.delete()
#     
#     def values(self, *limit_to, **kwargs):
#         #TODO cache
#         return self.query.values(*limit_to, **kwargs)
#     
#     def get(self, **kwargs):
#         #TODO cache
#         return self.query.get(**kwargs)
#     
#     def exists(self):
#         return self.query.exists()
#     
#     def __getitem__(self, val):
#         #TODO cache
#         return self.query.__getitem__(val)
#     
#     def __nonzero__(self):
#         #TODO cache
#         return self.query.__nonzero__()
#     
#     def __iter__(self):
#         return iter(self.query)


import copy
import hashlib
import json
from dockit.backends.queryset import QuerySet
            from dockit.schema import Document
            from django.db.models import Model
        from dockit.schema.loading import register_indexes
        from dockit.backends import get_index_router
            #TODO proper parsing
            key, operation = self._parse_key(key)
            items.append(QueryFilterOperation(key=key, operation=operation, value=value))
        return items
    
    def _add_filter_parts(self, inclusions=[], exclusions=[], indexes=[]):
        new_index = type(self)(self.document)
        new_index.inclusions = self.inclusions + inclusions
        new_index.exclusions = self.exclusions + exclusions
        new_index.indexes = self.indexes + indexes
        return new_index
    
    def _clone(self):
        return self._add_filter_parts()
    
    def _pk_only(self):
        for inclusion in self.inclusions:
            if inclusion.key != 'pk' or inclusion.operation != 'exact':
                return False
        for exclusion in self.exclusions:
            if exclusion.key != 'pk' or exclusion.operation != 'exact':
                return False
        return True
    
    def _build_queryset(self):
        if (not self._pk_only() and (self.inclusions or self.exclusions or self.indexes)):
            backend = self.document._meta.get_index_backend_for_read(self)
        else:
            backend = self.document._meta.get_document_backend_for_read()
        query = backend.get_query(self)

# Path: dockit/backends/queryset.py
# class QuerySet(object):
#     '''
#     Acts as a caching layer around an implemented `BaseDocumentQuery`
#     TODO: implement actual caching
#     '''
#     def __init__(self, query):
#         self.query = query
#     
#     @property
#     def document(self):
#         return self.query.document
#     
#     def __len__(self):
#         #TODO cache
#         return self.query.__len__()
#     
#     def count(self):
#         return self.__len__()
#     
#     def delete(self):
#         return self.query.delete()
#     
#     def values(self, *limit_to, **kwargs):
#         #TODO cache
#         return self.query.values(*limit_to, **kwargs)
#     
#     def get(self, **kwargs):
#         #TODO cache
#         return self.query.get(**kwargs)
#     
#     def exists(self):
#         return self.query.exists()
#     
#     def __getitem__(self, val):
#         #TODO cache
#         return self.query.__getitem__(val)
#     
#     def __nonzero__(self):
#         #TODO cache
#         return self.query.__nonzero__()
#     
#     def __iter__(self):
#         return iter(self.query)


# Path: dockit/backends/queryindex.py
import copy
import hashlib
import json
from dockit.backends.queryset import QuerySet
            from dockit.schema import Document
            from django.db.models import Model
        from dockit.schema.loading import register_indexes
        from dockit.backends import get_index_router

            #TODO proper parsing
            key, operation = self._parse_key(key)
            items.append(QueryFilterOperation(key=key, operation=operation, value=value))
        return items
    
    def _add_filter_parts(self, inclusions=[], exclusions=[], indexes=[]):
        new_index = type(self)(self.document)
        new_index.inclusions = self.inclusions + inclusions
        new_index.exclusions = self.exclusions + exclusions
        new_index.indexes = self.indexes + indexes
        return new_index
    
    def _clone(self):
        return self._add_filter_parts()
    
    def _pk_only(self):
        for inclusion in self.inclusions:
            if inclusion.key != 'pk' or inclusion.operation != 'exact':
                return False
        for exclusion in self.exclusions:
            if exclusion.key != 'pk' or exclusion.operation != 'exact':
                return False
        return True
    
    def _build_queryset(self):
        if (not self._pk_only() and (self.inclusions or self.exclusions or self.indexes)):
            backend = self.document._meta.get_index_backend_for_read(self)
        else:
            backend = self.document._meta.get_document_backend_for_read()
        query = backend.get_query(self)

        return QuerySet(query)