RLMFindOneAndModifyOptions.mm 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. ////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2020 Realm Inc.
  4. //
  5. // Licensed under the Apache License, Version 2.0 (the "License");
  6. // you may not use this file except in compliance with the License.
  7. // You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing, software
  12. // distributed under the License is distributed on an "AS IS" BASIS,
  13. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. // See the License for the specific language governing permissions and
  15. // limitations under the License.
  16. //
  17. ////////////////////////////////////////////////////////////////////////////
  18. #import "RLMFindOneAndModifyOptions_Private.hpp"
  19. #import "RLMBSON_Private.hpp"
  20. @interface RLMFindOneAndModifyOptions() {
  21. realm::app::MongoCollection::FindOneAndModifyOptions _options;
  22. };
  23. @end
  24. @implementation RLMFindOneAndModifyOptions
  25. - (instancetype)initWithProjection:(id<RLMBSON> _Nullable)projection
  26. sort:(id<RLMBSON> _Nullable)sort
  27. upsert:(BOOL)upsert
  28. shouldReturnNewDocument:(BOOL)shouldReturnNewDocument {
  29. if (self = [super init]) {
  30. self.upsert = upsert;
  31. self.shouldReturnNewDocument = shouldReturnNewDocument;
  32. self.projection = projection;
  33. self.sort = sort;
  34. }
  35. return self;
  36. }
  37. - (realm::app::MongoCollection::FindOneAndModifyOptions)_findOneAndModifyOptions {
  38. return _options;
  39. }
  40. - (id<RLMBSON>)projection {
  41. return RLMConvertBsonDocumentToRLMBSON(_options.projection_bson);
  42. }
  43. - (id<RLMBSON>)sort {
  44. return RLMConvertBsonDocumentToRLMBSON(_options.sort_bson);
  45. }
  46. - (BOOL)upsert {
  47. return _options.upsert;
  48. }
  49. - (BOOL)shouldReturnNewDocument {
  50. return _options.return_new_document;
  51. }
  52. - (void)setProjection:(id<RLMBSON>)projection {
  53. if (projection) {
  54. auto bson = realm::bson::BsonDocument(RLMConvertRLMBSONToBson(projection));
  55. _options.projection_bson = realm::util::Optional<realm::bson::BsonDocument>(bson);
  56. } else {
  57. _options.projection_bson = realm::util::none;
  58. }
  59. }
  60. - (void)setSort:(id<RLMBSON>)sort {
  61. if (sort) {
  62. auto bson = realm::bson::BsonDocument(RLMConvertRLMBSONToBson(sort));
  63. _options.sort_bson = realm::util::Optional<realm::bson::BsonDocument>(bson);
  64. } else {
  65. _options.sort_bson = realm::util::none;
  66. }
  67. }
  68. - (void)setUpsert:(BOOL)upsert {
  69. _options.upsert = upsert;
  70. }
  71. - (void)setShouldReturnNewDocument:(BOOL)returnNewDocument {
  72. _options.return_new_document = returnNewDocument;
  73. }
  74. @end