Stroika Library 3.0d18
 
Loading...
Searching...
No Matches
Database/Document/Collection.inl
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
6
7namespace Stroika::Foundation::Database::Document::Collection {
8
9 /*
10 ********************************************************************************
11 ************************* Document::Connection::Ptr ****************************
12 ********************************************************************************
13 */
14 inline Ptr::Ptr (const shared_ptr<IRep>& src)
15 : inherited{src}
16 {
17 }
18 inline Ptr& Ptr::operator= (const Ptr& src)
19 {
20 inherited::operator= (src);
21 return *this;
22 }
23 inline Ptr& Ptr::operator= (Ptr&& src) noexcept
24 {
25 inherited::operator= (src);
26 return *this;
27 }
28 inline auto Ptr::operator== (const Ptr& rhs) const
29 {
30 return get () == rhs.get ();
31 }
32 inline bool Ptr::operator== (nullptr_t) const noexcept
33 {
34 return this->get () == nullptr;
35 }
36 inline String Ptr::ToString () const
37 {
38 using namespace Characters;
39 return Format ("{}"_f, static_cast<const void*> (this->get ()));
40 }
41 inline IDType Ptr::Add (const Document& v)
42 {
43 return this->get ()->Add (v);
44 }
45 inline optional<Document> Ptr::GetOne (const IDType& id, const optional<Projection>& projection)
46 {
47 return this->get ()->GetOne (id, projection);
48 }
49 inline Document Ptr::GetOneOrThrow (const IDType& id, const optional<Projection>& projection)
50 {
51 static const auto kExcept_ = Execution::RuntimeErrorException{"no such id"sv};
52 return Memory::ValueOfOrThrow (GetOne (id, projection), kExcept_);
53 }
54 inline Sequence<Document> Ptr::GetAll (const optional<Filter>& filter, const optional<Projection>& projection)
55 {
56 return this->get ()->GetAll (filter, projection);
57 }
58 inline Sequence<IDType> Ptr::GetAllIDs (const optional<Filter>& filter)
59 {
60 return this->GetAll (filter, kOnlyIDs).Map<Sequence<IDType>> ([] (const Document& d) -> IDType {
61 static const auto kExcept_ = Execution::RuntimeErrorException{"no such id"sv};
62 return d.LookupChecked (kID, kExcept_).As<String> ();
63 });
64 }
65 inline void Ptr::Replace (const Document& newV)
66 {
67 Replace (Memory::ValueOf (newV.Lookup (kID)).As<String> (), newV);
68 }
69 inline void Ptr::Replace (const IDType& id, const Document& newV)
70 {
71 this->get ()->Update (id, newV, nullopt);
72 }
73 inline void Ptr::Update (const Document& newV)
74 {
75 Update (Memory::ValueOf (newV.Lookup (kID)).As<String> (), newV, Set<String>{newV.Keys ()});
76 }
77 inline void Ptr::Update (const Document& newV, const Set<String>& onlyTheseFields)
78 {
79 Update (Memory::ValueOf (newV.Lookup (kID)).As<String> (), newV, onlyTheseFields);
80 }
81 inline void Ptr::Update (const IDType& id, const Document& newV)
82 {
83 this->get ()->Update (id, newV, Set<String>{newV.Keys ()});
84 }
85 inline void Ptr::Update (const IDType& id, const Document& newV, const Set<String>& onlyTheseFields)
86 {
87 this->get ()->Update (id, newV, onlyTheseFields);
88 }
89 inline void Ptr::Remove (const IDType& id)
90 {
91 this->get ()->Remove (id);
92 }
93
94}
String is like std::u32string, except it is much easier to use, often much more space efficient,...
Definition String.h:201
nonvirtual optional< mapped_type > Lookup(ArgByValueType< key_type > key) const
Definition Mapping.inl:142
nonvirtual Iterable< key_type > Keys() const
Definition Mapping.inl:111
A generalization of a vector: a container whose elements are keyed by the natural numbers.
nonvirtual RESULT_CONTAINER Map(ELEMENT_MAPPER &&elementMapper) const
'override' Iterable<>::Map () function so RESULT_CONTAINER defaults to Sequence, and improve that cas...
Definition Sequence.inl:174
Set<T> is a container of T, where once an item is added, additionally adds () do nothing.