FIRTransaction.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <Foundation/Foundation.h>
  17. NS_ASSUME_NONNULL_BEGIN
  18. @class FIRDocumentReference;
  19. @class FIRDocumentSnapshot;
  20. @class FIRSetOptions;
  21. /**
  22. * `FIRTransaction` provides methods to read and write data within a transaction.
  23. *
  24. * @see FIRFirestore#transaction:completion:
  25. */
  26. NS_SWIFT_NAME(Transaction)
  27. @interface FIRTransaction : NSObject
  28. /** */
  29. - (id)init __attribute__((unavailable("FIRTransaction cannot be created directly.")));
  30. /**
  31. * Writes to the document referred to by `document`. If the document doesn't yet exist,
  32. * this method creates it and then sets the data. If the document exists, this method overwrites
  33. * the document data with the new values.
  34. *
  35. * @param data An `NSDictionary` that contains the fields and data to write to the document.
  36. * @param document A reference to the document whose data should be overwritten.
  37. * @return This `FIRTransaction` instance. Used for chaining method calls.
  38. */
  39. // clang-format off
  40. - (FIRTransaction *)setData:(NSDictionary<NSString *, id> *)data
  41. forDocument:(FIRDocumentReference *)document
  42. NS_SWIFT_NAME(setData(_:forDocument:));
  43. // clang-format on
  44. /**
  45. * Writes to the document referred to by `document`. If the document doesn't yet exist,
  46. * this method creates it and then sets the data. If you pass `FIRSetOptions`, the provided data
  47. * will be merged into an existing document.
  48. *
  49. * @param data An `NSDictionary` that contains the fields and data to write to the document.
  50. * @param document A reference to the document whose data should be overwritten.
  51. * @param options A `FIRSetOptions` used to configure the set behavior.
  52. * @return This `FIRTransaction` instance. Used for chaining method calls.
  53. */
  54. // clang-format off
  55. - (FIRTransaction *)setData:(NSDictionary<NSString *, id> *)data
  56. forDocument:(FIRDocumentReference *)document
  57. options:(FIRSetOptions *)options
  58. NS_SWIFT_NAME(setData(_:forDocument:options:));
  59. // clang-format on
  60. /**
  61. * Updates fields in the document referred to by `document`.
  62. * If the document does not exist, the transaction will fail.
  63. *
  64. * @param fields An `NSDictionary` containing the fields (expressed as an `NSString` or
  65. * `FIRFieldPath`) and values with which to update the document.
  66. * @param document A reference to the document whose data should be updated.
  67. * @return This `FIRTransaction` instance. Used for chaining method calls.
  68. */
  69. // clang-format off
  70. - (FIRTransaction *)updateData:(NSDictionary<id, id> *)fields
  71. forDocument:(FIRDocumentReference *)document
  72. NS_SWIFT_NAME(updateData(_:forDocument:));
  73. // clang-format on
  74. /**
  75. * Deletes the document referred to by `document`.
  76. *
  77. * @param document A reference to the document that should be deleted.
  78. * @return This `FIRTransaction` instance. Used for chaining method calls.
  79. */
  80. - (FIRTransaction *)deleteDocument:(FIRDocumentReference *)document
  81. NS_SWIFT_NAME(deleteDocument(_:));
  82. /**
  83. * Reads the document referenced by `document`.
  84. *
  85. * @param document A reference to the document to be read.
  86. * @param error An out parameter to capture an error, if one occurred.
  87. */
  88. - (FIRDocumentSnapshot *_Nullable)getDocument:(FIRDocumentReference *)document
  89. error:(NSError *__autoreleasing *)error
  90. NS_SWIFT_NAME(getDocument(_:));
  91. @end
  92. NS_ASSUME_NONNULL_END