def _get_refs_from(self, key, type_name, field_name): type_ref = self.db.collection(type_name) query_ref = type_ref.where(field_name, u'==', key) snapshots = self._stream_ref(query_ref) rows = [ResultWrapper.from_couchdb_json(self.value_from_snapshot(snapshot)) for snapshot in snapshots] objs = [GenericObject._from_doc(self, row.key, row.rev, row.value) for row in rows] return objs
def _get_refs_from(self, key, type_name, field_name): type_ref = self.db.collection(type_name) query_ref = type_ref.where(field_name, u'==', key) snapshots = query_ref.get() rows = [ResultWrapper.from_couchdb_json(self.value_from_snapshot(snapshot)) for snapshot in snapshots] objs = [GenericObject._from_doc(self, row.key, row.rev, row.value) for row in rows] return objs
def get_unique_instance(self, namespace, type_name, field_name, value): unique_type_name = "%s__%s" % (type_name, field_name) unique_doc_ref = self.db.collection(unique_type_name).document(value) try: doc = unique_doc_ref.get() as_dict = doc.to_dict() wrapper = self._get(as_dict["owner"], as_dict["type_name"]) return GenericObject._from_doc(self, wrapper.key, wrapper.rev, wrapper.value) except NotFound: return None
def get_unique_instance(self, namespace, type_name, field_name, value): unique_type_name = "%s__%s" % (type_name, field_name) unique_doc_ref = self.db.collection(unique_type_name).document(value) doc = self._get_ref(unique_doc_ref) if doc.exists: as_dict = doc.to_dict() wrapper = self._get(as_dict["owner"], as_dict["type_name"]) return GenericObject._from_doc(self, wrapper.key, wrapper.rev, wrapper.value) else: return None
def get_single_type(self, namespace, type_name): type_ref = self.db.collection(type_name) snapshots = self._stream_ref(type_ref) rows = [ ResultWrapper.from_couchdb_json(self.value_from_snapshot(snapshot)) for snapshot in snapshots ] objs = [ GenericObject._from_doc(self, row.key, row.rev, row.value) for row in rows ] return objs
def get_single_type(self, namespace, type_name): type_ref = self.db.collection(type_name) docs = type_ref.get() rows = [ResultWrapper.from_couchdb_json(doc.to_dict()) for doc in docs] objs = [GenericObject._from_doc(self, row.key, row.rev, row.value) for row in rows] return objs