def convert_set_option(option):
    from google.cloud.firestore_v1 import _helpers

    if option.fields:
        return [
            _helpers.FieldPath(*field.field).to_api_repr() for field in option.fields
        ]

    assert option.all_
    return True
Exemplo n.º 2
0
    def _write_pb_for_set(document_path, document_data, merge):
        from google.cloud.firestore_v1.types import common
        from google.cloud.firestore_v1.types import document
        from google.cloud.firestore_v1.types import write
        from google.cloud.firestore_v1 import _helpers

        write_pbs = write.Write(update=document.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.DocumentMask(field_paths=sorted(field_paths))
            write_pbs._pb.update_mask.CopyFrom(mask._pb)
        return write_pbs