def convert_set_option(option): from google.cloud.firestore_v1beta1 import _helpers if option.fields: return [ _helpers.FieldPath(*field.field).to_api_repr() for field in option.fields ] assert option.all return True
def _write_pb_for_set(document_path, document_data, merge): from google.cloud.firestore_v1beta1.proto import common_pb2 from google.cloud.firestore_v1beta1.proto import document_pb2 from google.cloud.firestore_v1beta1.proto import write_pb2 from google.cloud.firestore_v1beta1 import _helpers write_pbs = write_pb2.Write(update=document_pb2.Document( name=document_path, fields=_helpers.encode_dict(document_data))) if merge: field_paths = [ field_path for field_path, value in _helpers.extract_fields( document_data, _helpers.FieldPath()) ] field_paths = [ field_path.to_api_repr() for field_path in sorted(field_paths) ] mask = common_pb2.DocumentMask(field_paths=sorted(field_paths)) write_pbs.update_mask.CopyFrom(mask) return write_pbs