Stroika Library 3.0d23x
 
Loading...
Searching...
No Matches
ObjectCollection.inl
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2026. 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 auto Ptr<T>::Add (const T& v) const -> IDType
20 {
21 return inherited::Add (fMapper_.FromObject (v).template As<Mapping<String, VariantValue>> ());
22 }
23 template <typename T>
24 inline optional<T> Ptr<T>::Get (const IDType& id, const optional<Projection>& projection) const
25 {
26 if (optional<Document> o = inherited::Get (id, projection)) {
27 return fMapper_.ToObject<T> (VariantValue{*o});
28 }
29 else {
30 return nullopt;
31 }
32 }
33 template <typename T>
34 inline optional<T> Ptr<T>::Get (const Filter& filter, const optional<Projection>& projection) const
35 {
36 if (optional<Document> o = inherited::Get (filter, projection)) {
37 return fMapper_.ToObject<T> (VariantValue{*o});
38 }
39 else {
40 return nullopt;
41 }
42 }
43 template <typename T>
44 inline T Ptr<T>::GetOrThrow (const IDType& id, const optional<Projection>& projection) const
45 {
46 return fMapper_.ToObject<T> (VariantValue{inherited::GetOrThrow (id, projection)});
47 }
48 template <typename T>
49 inline T Ptr<T>::GetOrThrow (const Filter& filter, const optional<Projection>& projection) const
50 {
51 return fMapper_.ToObject<T> (VariantValue{inherited::GetOrThrow (filter, projection)});
52 }
53 template <typename T>
54 Sequence<T> Ptr<T>::GetAll (const optional<Filter>& filter, const optional<Projection>& projection) const
55 {
56 return inherited::GetAll (filter, projection).template Map<Sequence<T>> ([this] (const Document& d) {
57 return fMapper_.ToObject<T> (VariantValue{d});
58 });
59 }
60 template <typename T>
61 inline void Ptr<T>::Replace (const T& newV) const
62 {
63 inherited::Replace (fMapper_.FromObject (newV).template As<Mapping<String, VariantValue>> ());
64 }
65 template <typename T>
66 inline void Ptr<T>::Replace (const IDType& id, const T& newV) const
67 {
68 inherited::Replace (id, fMapper_.FromObject (newV).template As<Mapping<String, VariantValue>> ());
69 }
70 template <typename T>
71 inline void Ptr<T>::Update (const T& newV, const Set<String>& onlyTheseFields) const
72 {
73 inherited::Update (fMapper_.FromObject (newV).template As<Mapping<String, VariantValue>> (), onlyTheseFields);
74 }
75 template <typename T>
76 inline void Ptr<T>::Update (const IDType& id, const T& newV, const Set<String>& onlyTheseFields) const
77 {
78 inherited::Update (id, fMapper_.FromObject (newV).template As<Mapping<String, VariantValue>> (), onlyTheseFields);
79 }
80 template <typename T>
81 inline auto Ptr<T>::AddOrUpdate (const T& newV) const -> IDType
82 {
83 return inherited::AddOrUpdate (fMapper_.FromObject (newV).template As<Mapping<String, VariantValue>> ());
84 }
85
86 /*
87 ********************************************************************************
88 ********************* Document::ObjectCollection::New **************************
89 ********************************************************************************
90 */
91 template <typename T>
92 inline Ptr<T> New (const Database::Document::Collection::Ptr& underlyingCollection, const ObjectVariantMapper& mapper)
93 {
94 return Ptr<T>{underlyingCollection, mapper};
95 }
96
97}
Mapping< String, VariantValue > Document
Definition Document.h:28