def get(self, cls, obj_id): cls_info = get_cls_info(cls) collection = cls_info.get_collection(self) obj = self._cache.get((cls_info, obj_id)) if obj is not None: return obj cursor = self._load(cls_info, collection.find, {'_id': obj_id}, limit=2) if cursor.count(): return self._build_doc(cls_info, cursor[0])
def getCollection(self, cls): return get_cls_info(cls).get_collection(self.store)
def find(self, cls, *args, **kwargs): cls_info = get_cls_info(cls) collection = cls_info.get_collection(self) cursor = self._load(cls_info, collection.find, *args, **kwargs) for item in cursor: yield self._build_doc(cls_info, item)
def drop_collection(self, cls): cls_info = get_cls_info(cls) collection = cls_info.get_collection(self) collection.drop()
def count(self, cls): cls_info = get_cls_info(cls) collection = cls_info.get_collection(self) return collection.find().count()
def find_one_by(self, cls, **kwargs): cls_info = get_cls_info(cls) collection = cls_info.get_collection(self) item = self._load(cls_info, collection.find_one, **kwargs) if item is not None: return self._build_doc(cls_info, item)