FIRTransaction.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. * `Transaction` provides methods to read and write data within a transaction.
  22. *
  23. * @see `Firestore.runTransaction(_:)`
  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 A `Dictionary` 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 `Transaction` 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:true`, the provided data will
  46. * be merged into any existing document.
  47. *
  48. * @param data A `Dictionary` 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. If enabled,
  51. * all omitted fields remain untouched. If your input sets any field to an empty dictionary, any
  52. * nested field is overwritten.
  53. * @return This `Transaction` instance. Used for chaining method calls.
  54. */
  55. // clang-format off
  56. - (FIRTransaction *)setData:(NSDictionary<NSString *, id> *)data
  57. forDocument:(FIRDocumentReference *)document
  58. merge:(BOOL)merge
  59. NS_SWIFT_NAME(setData(_:forDocument:merge:));
  60. // clang-format on
  61. /**
  62. * Writes to the document referred to by `document` and only replace the fields
  63. * specified under `mergeFields`. Any field that is not specified in `mergeFields`
  64. * is ignored and remains untouched. If the document doesn't yet exist,
  65. * this method creates it and then sets the data.
  66. *
  67. * It is an error to include a field in `mergeFields` that does not have a corresponding
  68. * value in the `data` dictionary.
  69. *
  70. * @param data A `Dictionary` containing the fields that make up the document
  71. * to be written.
  72. * @param document A reference to the document whose data should be overwritten.
  73. * @param mergeFields An `Array` that contains a list of `String` or `FieldPath` elements
  74. * specifying which fields to merge. Fields can contain dots to reference nested fields within
  75. * the document. If your input sets any field to an empty dictionary, any nested field is
  76. * overwritten.
  77. * @return This `Transaction` instance. Used for chaining method calls.
  78. */
  79. // clang-format off
  80. - (FIRTransaction *)setData:(NSDictionary<NSString *, id> *)data
  81. forDocument:(FIRDocumentReference *)document
  82. mergeFields:(NSArray<id> *)mergeFields
  83. NS_SWIFT_NAME(setData(_:forDocument:mergeFields:));
  84. // clang-format on
  85. /**
  86. * Updates fields in the document referred to by `document`.
  87. * If the document does not exist, the transaction will fail.
  88. *
  89. * @param fields A `Dictionary` containing the fields (expressed as an `String` or
  90. * `FieldPath`) and values with which to update the document.
  91. * @param document A reference to the document whose data should be updated.
  92. * @return This `Transaction` instance. Used for chaining method calls.
  93. */
  94. // clang-format off
  95. - (FIRTransaction *)updateData:(NSDictionary<id, id> *)fields
  96. forDocument:(FIRDocumentReference *)document
  97. NS_SWIFT_NAME(updateData(_:forDocument:));
  98. // clang-format on
  99. /**
  100. * Deletes the document referred to by `document`.
  101. *
  102. * @param document A reference to the document that should be deleted.
  103. * @return This `Transaction` instance. Used for chaining method calls.
  104. */
  105. - (FIRTransaction *)deleteDocument:(FIRDocumentReference *)document
  106. NS_SWIFT_NAME(deleteDocument(_:));
  107. /**
  108. * Reads the document referenced by `document`.
  109. *
  110. * @param document A reference to the document to be read.
  111. * @param error An out parameter to capture an error, if one occurred.
  112. */
  113. - (FIRDocumentSnapshot *_Nullable)getDocument:(FIRDocumentReference *)document
  114. error:(NSError *__autoreleasing *)error
  115. NS_SWIFT_NAME(getDocument(_:));
  116. @end
  117. NS_ASSUME_NONNULL_END