Stroika Library 3.0d18
 
Loading...
Searching...
No Matches
ObjectCollection.inl
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4
5namespace Stroika::Foundation::Database::Document::ObjectCollection {
6
7 /*
8 ********************************************************************************
9 ********************* Document::ObjectCollection::Ptr **************************
10 ********************************************************************************
11 */
12 template <typename T>
13 inline Ptr<T>::Ptr (const Database::Document::Collection::Ptr& underlyingCollection, const ObjectVariantMapper& mapper)
14 : inherited{underlyingCollection}
15 , fMapper_{mapper}
16 {
17 }
18 template <typename T>
19 inline String Ptr<T>::Add (const T& v)
20 {
21 return inherited::Add (fMapper_.FromObject (v).template As<Mapping<String, VariantValue>> ());
22 }
23 template <typename T>
24 inline optional<T> Ptr<T>::GetOne (const IDType& id, const optional<Projection>& projection)
25 {
26 if (optional<Document> o = inherited::GetOne (id, projection)) {
27 return fMapper_.ToObject<T> (VariantValue{*o});
28 }
29 else {
30 return nullopt;
31 }
32 }
33 template <typename T>
34 inline T Ptr<T>::GetOneOrThrow (const IDType& id, const optional<Projection>& projection)
35 {
36 return fMapper_.ToObject<T> (VariantValue{inherited::GetOneOrThrow (id, projection)});
37 }
38 template <typename T>
39 Sequence<T> Ptr<T>::GetAll (const optional<Filter>& filter, const optional<Projection>& projection)
40 {
41 return inherited::GetAll (filter, projection).template Map<Sequence<T>> ([this] (const Document& d) {
42 return fMapper_.ToObject<T> (VariantValue{d});
43 });
44 }
45 template <typename T>
46 inline void Ptr<T>::Replace (const T& newV)
47 {
48 inherited::Replace (fMapper_.FromObject (newV).template As<Mapping<String, VariantValue>> ());
49 }
50 template <typename T>
51 inline void Ptr<T>::Replace (const IDType& id, const T& newV)
52 {
53 inherited::Replace (id, fMapper_.FromObject (newV).template As<Mapping<String, VariantValue>> ());
54 }
55 template <typename T>
56 inline void Ptr<T>::Update (const T& newV, const Set<String>& onlyTheseFields)
57 {
58 inherited::Update (fMapper_.FromObject (newV).template As<Mapping<String, VariantValue>> (), onlyTheseFields);
59 }
60 template <typename T>
61 inline void Ptr<T>::Update (const IDType& id, const T& newV, const Set<String>& onlyTheseFields)
62 {
63 inherited::Update (id, fMapper_.FromObject (newV).template As<Mapping<String, VariantValue>> (), onlyTheseFields);
64 }
65
66 /*
67 ********************************************************************************
68 ********************* Document::ObjectCollection::New **************************
69 ********************************************************************************
70 */
71 template <typename T>
72 inline Ptr<T> New (const Database::Document::Collection::Ptr& underlyingCollection, const ObjectVariantMapper& mapper)
73 {
74 return Ptr<T>{underlyingCollection, mapper};
75 }
76
77}
Mapping< String, VariantValue > Document
Definition Document.h:28