FIRTransaction.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. /**
  21. * `FIRTransaction` provides methods to read and write data within a transaction.
  22. *
  23. * @see FIRFirestore#transaction:completion:
  24. */
  25. NS_SWIFT_NAME(Transaction)
  26. @interface FIRTransaction : NSObject
  27. /** :nodoc: */
  28. - (id)init __attribute__((unavailable("FIRTransaction cannot be created directly.")));
  29. /**
  30. * Writes to the document referred to by `document`. If the document doesn't yet exist,
  31. * this method creates it and then sets the data. If the document exists, this method overwrites
  32. * the document data with the new values.
  33. *
  34. * @param data An `NSDictionary` that contains the fields and data to write to the document.
  35. * @param document A reference to the document whose data should be overwritten.
  36. * @return This `FIRTransaction` instance. Used for chaining method calls.
  37. */
  38. // clang-format off
  39. - (FIRTransaction *)setData:(NSDictionary<NSString *, id> *)data
  40. forDocument:(FIRDocumentReference *)document
  41. NS_SWIFT_NAME(setData(_:forDocument:));
  42. // clang-format on
  43. /**
  44. * Writes to the document referred to by `document`. If the document doesn't yet exist,
  45. * this method creates it and then sets the data. If you pass `merge:YES`, the provided data will be
  46. * merged into any existing document.
  47. *
  48. * @param data An `NSDictionary` that contains the fields and data to write to the document.
  49. * @param document A reference to the document whose data should be overwritten.
  50. * @param merge Whether to merge the provided data into any existing document.
  51. * @return This `FIRTransaction` instance. Used for chaining method calls.
  52. */
  53. // clang-format off
  54. - (FIRTransaction *)setData:(NSDictionary<NSString *, id> *)data
  55. forDocument:(FIRDocumentReference *)document
  56. merge:(BOOL)merge
  57. NS_SWIFT_NAME(setData(_:forDocument:merge:));
  58. // clang-format on
  59. /**
  60. * Writes to the document referred to by `document` and only replace the fields
  61. * specified under `mergeFields`. Any field that is not specified in `mergeFields`
  62. * is ignored and remains untouched. If the document doesn't yet exist,
  63. * this method creates it and then sets the data.
  64. *
  65. * It is an error to include a field in `mergeFields` that does not have a corresponding
  66. * value in the `data` dictionary.
  67. *
  68. * @param data An `NSDictionary` containing the fields that make up the document
  69. * to be written.
  70. * @param document A reference to the document whose data should be overwritten.
  71. * @param mergeFields An `NSArray` that contains a list of `NSString` or `FIRFieldPath` elements
  72. * specifying which fields to merge. Fields can contain dots to reference nested fields within
  73. * the document.
  74. * @return This `FIRTransaction` instance. Used for chaining method calls.
  75. */
  76. // clang-format off
  77. - (FIRTransaction *)setData:(NSDictionary<NSString *, id> *)data
  78. forDocument:(FIRDocumentReference *)document
  79. mergeFields:(NSArray<id> *)mergeFields
  80. NS_SWIFT_NAME(setData(_:forDocument:mergeFields:));
  81. // clang-format on
  82. /**
  83. * Updates fields in the document referred to by `document`.
  84. * If the document does not exist, the transaction will fail.
  85. *
  86. * @param fields An `NSDictionary` containing the fields (expressed as an `NSString` or
  87. * `FIRFieldPath`) and values with which to update the document.
  88. * @param document A reference to the document whose data should be updated.
  89. * @return This `FIRTransaction` instance. Used for chaining method calls.
  90. */
  91. // clang-format off
  92. - (FIRTransaction *)updateData:(NSDictionary<id, id> *)fields
  93. forDocument:(FIRDocumentReference *)document
  94. NS_SWIFT_NAME(updateData(_:forDocument:));
  95. // clang-format on
  96. /**
  97. * Deletes the document referred to by `document`.
  98. *
  99. * @param document A reference to the document that should be deleted.
  100. * @return This `FIRTransaction` instance. Used for chaining method calls.
  101. */
  102. - (FIRTransaction *)deleteDocument:(FIRDocumentReference *)document
  103. NS_SWIFT_NAME(deleteDocument(_:));
  104. /**
  105. * Reads the document referenced by `document`.
  106. *
  107. * @param document A reference to the document to be read.
  108. * @param error An out parameter to capture an error, if one occurred.
  109. */
  110. - (FIRDocumentSnapshot *_Nullable)getDocument:(FIRDocumentReference *)document
  111. error:(NSError *__autoreleasing *)error
  112. NS_SWIFT_NAME(getDocument(_:));
  113. @end
  114. NS_ASSUME_NONNULL_END