def get( cls, document_id: str, *, firestore_client: FirestoreClient ) -> _DocumentSubclassTypeVar: path = [cls.__firestore__.collection, document_id] snapshot = DocumentReference(*path, client=firestore_client).get() if snapshot is None: return None else: return cls._from_firestore_snapshot( snapshot, firestore_client=firestore_client )
def check_if_playlist_exists(profile: DocumentReference, name: str): data_snapshot: DocumentSnapshot = profile.get() data: dict = data_snapshot.to_dict() if data is not None: if "playlists" in data.keys(): playlists: list = data["playlists"] playlist: dict for playlist in playlists: if playlist["name"]: if playlist["name"].lower() == name.lower(): return playlist["ref"] return False else: return False else: return False
def parse_cursor(cursor, client): from google.cloud.firestore_v1 import DocumentReference from google.cloud.firestore_v1 import DocumentSnapshot if "doc_snapshot" in cursor: path = parse_path(cursor.doc_snapshot.path) doc_ref = DocumentReference(*path, client=client) return DocumentSnapshot( reference=doc_ref, data=json.loads(cursor.doc_snapshot.json_data), exists=True, read_time=None, create_time=None, update_time=None, ) values = [json.loads(value) for value in cursor.json_values] return convert_data(values)
def doc_ref(self, create: bool = False, new_id: bool = False) -> DocumentReference: id_ = self._document_id(create=create, new_id=new_id) path = [self.__firestore__.collection, id_] return DocumentReference(*path, client=self.__firestore__.client)