def _query_items_simple(self, firebase_query): snapshots = self._stream_ref(firebase_query) results = [] for snapshot in snapshots: wrapper = ResultWrapper.from_couchdb_json(self.value_from_snapshot(snapshot)) results.append(GenericObject.from_row(self, wrapper)) return results
def _query_items_simple(self, firebase_query): snapshots = firebase_query.get() results = [] for snapshot in snapshots: wrapper = ResultWrapper.from_couchdb_json(self.value_from_snapshot(snapshot)) results.append(GenericObject.from_row(self, wrapper)) return results
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 query_items_iterator(self, firebase_query, batch_size, order_by=u'_id'): for snapshot in self.query_snapshots_iterator(firebase_query, batch_size=batch_size, order_by=order_by): wrapper = ResultWrapper.from_couchdb_json( self.value_from_snapshot(snapshot)) obj = GenericObject.from_row(self, wrapper) yield obj
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_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 changes(self, since=None, channels=None, limit=None, feed=None, timeout=None, filter=None): return GenericObject.changes(self, since=since, channels=channels, limit=limit, feed=feed, timeout=timeout, filter=filter)
def delete_key(self, key): return GenericObject.delete_key(self, key)
def query_view(self, view_name, **kwargs): return GenericObject.view(self, view_name, **kwargs)
def get(self, key, class_name=None): return GenericObject.get(self, key, class_name=class_name)
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
def query_items_iterator(self, firebase_query, batch_size, order_by=u'_id'): for snapshot in self.query_snapshots_iterator(firebase_query, batch_size=batch_size, order_by=order_by): wrapper = ResultWrapper.from_couchdb_json(self.value_from_snapshot(snapshot)) obj = GenericObject.from_row(self, wrapper) yield obj